@@ -6,8 +6,6 @@ import { CompanyInsightsController } from "../../lib/controllers/company-insight
66describe ( "companyInsightsController" , ( ) => {
77 const insightsUrlEndpoint = "/api/insights?ipAddress=%s" ;
88 const currentIp = "8.8.8.8" ;
9- const profileDir = "profileDir" ;
10- const cacheTimeout = 30 * 24 * 60 * 60 * 1000 ; // 2 days in milliseconds
119 const defaultCompanyData = {
1210 company : {
1311 name : "Progress" ,
@@ -29,26 +27,6 @@ describe("companyInsightsController", () => {
2927 employeeCount : "500"
3028 } ;
3129
32- const defaultExpectedDataPassedToGetSetting : any [ ] = [ { settingName : `companyInformation_${ currentIp } ` , cacheOpts : { cacheTimeout } } ] ;
33- const defaultExpectedDataPassedToSaveSetting : any [ ] = [
34- {
35- cacheOpts : {
36- useCaching : true
37- } ,
38- key : "companyInformation_8.8.8.8" ,
39- value : {
40- country : "Bulgaria" ,
41- employeeCount : "500" ,
42- industries : "Software__Software 2" ,
43- name : "Progress" ,
44- revenue : "123131"
45- }
46- }
47- ] ;
48-
49- let dataPassedToGetSettingValue : { settingName : string , cacheOpts ?: ICacheTimeoutOpts } [ ] = [ ] ;
50- let dataPassedToSaveSettingValue : { key : string , value : any , cacheOpts ?: IUseCacheOpts } [ ] = [ ] ;
51- let getSettingValueResult : IDictionary < any > = null ;
5230 let httpRequestCounter = 0 ;
5331 let httpRequestResult : any = null ;
5432 let testInjector : IInjector = null ;
@@ -68,43 +46,24 @@ describe("companyInsightsController", () => {
6846 } ) ;
6947
7048 injector . register ( "logger" , LoggerStub ) ;
71- injector . register ( "injector" , injector ) ;
7249 injector . register ( "ipService" , {
7350 getCurrentIPv4Address : async ( ) : Promise < string > => currentIp
7451 } ) ;
7552
76- injector . register ( "settingsService" , {
77- getProfileDir : ( ) : string => profileDir
78- } ) ;
79-
80- injector . register ( "jsonFileSettingsService" , {
81- getSettingValue : async ( settingName : string , cacheOpts ?: ICacheTimeoutOpts ) : Promise < any > => {
82- dataPassedToGetSettingValue . push ( { settingName, cacheOpts } ) ;
83- return getSettingValueResult ;
84- } ,
85-
86- saveSetting : async ( key : string , value : any , cacheOpts ?: IUseCacheOpts ) : Promise < void > => {
87- dataPassedToSaveSettingValue . push ( { key, value, cacheOpts } ) ;
88- }
89- } ) ;
90-
9153 injector . register ( "companyInsightsController" , CompanyInsightsController ) ;
9254
9355 return injector ;
9456 } ;
9557
9658 beforeEach ( ( ) => {
97- dataPassedToGetSettingValue = [ ] ;
98- dataPassedToSaveSettingValue = [ ] ;
99- getSettingValueResult = null ;
10059 httpRequestCounter = 0 ;
10160 httpRequestResult = defaultCompanyData ;
10261 testInjector = createTestInjector ( ) ;
10362 companyInsightsController = testInjector . resolve < ICompanyInsightsController > ( "companyInsightsController" ) ;
10463 } ) ;
10564
10665 describe ( "getCompanyData" , ( ) => {
107- describe ( "returns null when data does not exist in the cache and " , ( ) => {
66+ describe ( "returns null when" , ( ) => {
10867 it ( "the http client fails to get data" , async ( ) => {
10968 const httpClient = testInjector . resolve < Server . IHttpClient > ( "httpClient" ) ;
11069 const errMsg = "custom error" ;
@@ -146,31 +105,13 @@ describe("companyInsightsController", () => {
146105 const companyData = await companyInsightsController . getCompanyData ( ) ;
147106 assert . deepEqual ( companyData , null ) ;
148107 assert . equal ( httpRequestCounter , 0 , "We should not have any http request" ) ;
149- assert . deepEqual ( dataPassedToGetSettingValue , [ ] , "When we are unable to get IP, we should not try to get value from the cache." ) ;
150- assert . deepEqual ( dataPassedToSaveSettingValue , [ ] , "When we are unable to get IP, we should not persist anything." ) ;
151108 } ) ;
152109 } ) ;
153110
154111 describe ( "returns correct data when" , ( ) => {
155- it ( "data for current ip exist in the cache" , async ( ) => {
156- httpRequestResult = null ;
157-
158- getSettingValueResult = defaultExpectedCompanyData ; // data in the file should be in the already parsed format
159- const companyData = await companyInsightsController . getCompanyData ( ) ;
160- assert . deepEqual ( companyData , defaultExpectedCompanyData ) ;
161-
162- assert . equal ( httpRequestCounter , 0 , "In case we have data for the company in our cache, we should not make any http requests" ) ;
163- assert . deepEqual ( dataPassedToGetSettingValue , defaultExpectedDataPassedToGetSetting ) ;
164- assert . deepEqual ( dataPassedToSaveSettingValue , [ ] ) ;
165- } ) ;
166-
167- describe ( "data for current ip does not exist in the cache and" , ( ) => {
168-
169112 it ( "response contains company property" , async ( ) => {
170113 const companyData = await companyInsightsController . getCompanyData ( ) ;
171114 assert . deepEqual ( companyData , defaultExpectedCompanyData ) ;
172- assert . deepEqual ( dataPassedToGetSettingValue , defaultExpectedDataPassedToGetSetting ) ;
173- assert . deepEqual ( dataPassedToSaveSettingValue , defaultExpectedDataPassedToSaveSetting ) ;
174115 } ) ;
175116
176117 it ( "response contains company property and industries in it are not populated" , async ( ) => {
@@ -191,26 +132,8 @@ describe("companyInsightsController", () => {
191132 industries : null ,
192133 employeeCount : "500"
193134 } ) ;
194-
195- assert . deepEqual ( dataPassedToGetSettingValue , defaultExpectedDataPassedToGetSetting ) ;
196- assert . deepEqual ( dataPassedToSaveSettingValue , [
197- {
198- cacheOpts : {
199- useCaching : true
200- } ,
201- key : "companyInformation_8.8.8.8" ,
202- value : {
203- country : "Bulgaria" ,
204- employeeCount : "500" ,
205- industries : null ,
206- name : "Progress" ,
207- revenue : "123131"
208- }
209- }
210- ] ) ;
211135 } ) ;
212136
213- } ) ;
214137 } ) ;
215138
216139 it ( "is called only once per process" , async ( ) => {
0 commit comments