@@ -4,10 +4,10 @@ import { LoggerStub } from "../stubs";
44import { CompanyInsightsController } from "../../lib/controllers/company-insights-controller" ;
55
66describe ( "companyInsightsController" , ( ) => {
7- const insightsUrlEndpoint = "/api/insights" ;
7+ const insightsUrlEndpoint = "/api/insights?ipAddress=%s " ;
88 const currentIp = "8.8.8.8" ;
99 const profileDir = "profileDir" ;
10- const cacheTimeout = 48 * 60 * 60 * 1000 ; // 2 days in milliseconds
10+ const cacheTimeout = 30 * 24 * 60 * 60 * 1000 ; // 2 days in milliseconds
1111 const defaultCompanyData = {
1212 company : {
1313 name : "Progress" ,
@@ -138,6 +138,17 @@ describe("companyInsightsController", () => {
138138 const companyData = await companyInsightsController . getCompanyData ( ) ;
139139 assert . deepEqual ( companyData , null ) ;
140140 } ) ;
141+
142+ it ( "unable to get current ip address" , async ( ) => {
143+ const ipService = testInjector . resolve < IIPService > ( "ipService" ) ;
144+ ipService . getCurrentIPv4Address = async ( ) : Promise < string > => { throw new Error ( "Unable to get current ip addreess" ) ; } ;
145+
146+ const companyData = await companyInsightsController . getCompanyData ( ) ;
147+ assert . deepEqual ( companyData , null ) ;
148+ 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." ) ;
151+ } ) ;
141152 } ) ;
142153
143154 describe ( "returns correct data when" , ( ) => {
@@ -155,17 +166,6 @@ describe("companyInsightsController", () => {
155166
156167 describe ( "data for current ip does not exist in the cache and" , ( ) => {
157168
158- it ( "unable to get current ip address, but still can get company information" , async ( ) => {
159- const ipService = testInjector . resolve < IIPService > ( "ipService" ) ;
160- ipService . getCurrentIPv4Address = async ( ) : Promise < string > => { throw new Error ( "Unable to get current ip addreess" ) ; } ;
161-
162- const companyData = await companyInsightsController . getCompanyData ( ) ;
163- assert . deepEqual ( companyData , defaultExpectedCompanyData ) ;
164- assert . equal ( httpRequestCounter , 1 , "We should have only one http request" ) ;
165- assert . deepEqual ( dataPassedToGetSettingValue , [ ] , "When we are unable to get IP, we should not try to get value from the cache." ) ;
166- assert . deepEqual ( dataPassedToSaveSettingValue , [ ] , "When we are unable to get IP, we should not persist anything." ) ;
167- } ) ;
168-
169169 it ( "response contains company property" , async ( ) => {
170170 const companyData = await companyInsightsController . getCompanyData ( ) ;
171171 assert . deepEqual ( companyData , defaultExpectedCompanyData ) ;
0 commit comments