@@ -37,12 +37,12 @@ describe('internal #getSettings', () => {
3737 afterEach ( ( ) => {
3838 jest . clearAllMocks ( ) ;
3939 } ) ;
40-
40+
4141 it . each ( [
4242 [ false , false ] , // No proxy, No segment endpoint
43- [ false , true ] , // No proxy, Yes segment endpoint
44- [ true , false ] , // Yes proxy, No segment endpoint
45- [ true , true ] , // Yes proxy, Yes segment endpoint
43+ [ false , true ] , // No proxy, Yes segment endpoint
44+ [ true , false ] , // Yes proxy, No segment endpoint
45+ [ true , true ] , // Yes proxy, Yes segment endpoint
4646 ] ) (
4747 'fetches the settings successfully when hasProxy is %s and useSegmentEndpoints is %s' ,
4848 async ( hasProxy , useSegmentEndpoints ) => {
@@ -51,188 +51,208 @@ describe('internal #getSettings', () => {
5151 ok : true ,
5252 json : ( ) => mockJSONResponse ,
5353 } ) ;
54-
54+
5555 // Mock global fetch function
5656 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5757 // @ts -ignore
5858 global . fetch = jest . fn ( ( ) => Promise . resolve ( mockResponse ) ) ;
59-
59+
6060 // Set up config based on test parameters
6161 const config = {
6262 ...clientArgs . config ,
6363 useSegmentEndpoints,
6464 cdnProxy : hasProxy ? 'https://custom-proxy.com' : undefined , // Set proxy only when true
6565 } ;
66-
66+
6767 // Create client with the dynamic config
6868 const client = new SegmentClient ( {
6969 ...clientArgs ,
7070 config,
7171 } ) ;
72-
72+
7373 await client . fetchSettings ( ) ;
74-
74+
7575 // Determine expected settings URL based on the logic
7676 const settingsPrefix = config . cdnProxy ?? settingsCDN ;
7777 const expectedSettingsPath =
7878 hasProxy && useSegmentEndpoints
7979 ? `/projects/${ config . writeKey } /settings`
8080 : `/${ config . writeKey } /settings` ;
81-
82- expect ( fetch ) . toHaveBeenCalledWith ( getURL ( settingsPrefix , expectedSettingsPath ) , {
83- headers : {
84- 'Cache-Control' : 'no-cache' ,
85- } ,
86- } ) ;
87-
88- expect ( setSettingsSpy ) . toHaveBeenCalledWith ( mockJSONResponse . integrations ) ;
81+
82+ expect ( fetch ) . toHaveBeenCalledWith (
83+ getURL ( settingsPrefix , expectedSettingsPath ) ,
84+ {
85+ headers : {
86+ 'Cache-Control' : 'no-cache' ,
87+ } ,
88+ }
89+ ) ;
90+
91+ expect ( setSettingsSpy ) . toHaveBeenCalledWith (
92+ mockJSONResponse . integrations
93+ ) ;
8994 expect ( store . settings . get ( ) ) . toEqual ( mockJSONResponse . integrations ) ;
9095 expect ( client . settings . get ( ) ) . toEqual ( mockJSONResponse . integrations ) ;
9196 }
9297 ) ;
9398
9499 it . each ( [
95100 [ false , false ] , // No proxy, No segment endpoint
96- [ false , true ] , // No proxy, Yes segment endpoint
97- [ true , false ] , // Yes proxy, No segment endpoint
98- [ true , true ] , // Yes proxy, Yes segment endpoint
101+ [ false , true ] , // No proxy, Yes segment endpoint
102+ [ true , false ] , // Yes proxy, No segment endpoint
103+ [ true , true ] , // Yes proxy, Yes segment endpoint
99104 ] ) (
100105 'fails to fetch settings and falls back to defaults when hasProxy is %s and useSegmentEndpoints is %s' ,
101106 async ( hasProxy , useSegmentEndpoints ) => {
102107 // Mock fetch to reject (simulate failure)
103108 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
104109 // @ts -ignore
105110 global . fetch = jest . fn ( ( ) => Promise . reject ( ) ) ;
106-
111+
107112 // Set up config dynamically
108113 const config = {
109114 ...clientArgs . config ,
110115 useSegmentEndpoints,
111116 cdnProxy : hasProxy ? 'https://custom-proxy.com' : undefined , // Set proxy only when true
112117 } ;
113-
118+
114119 // Create client with the dynamic config
115120 const client = new SegmentClient ( {
116121 ...clientArgs ,
117122 config,
118123 } ) ;
119-
124+
120125 await client . fetchSettings ( ) ;
121-
126+
122127 // Determine expected settings URL
123128 const settingsPrefix = config . cdnProxy ?? settingsCDN ;
124129 const expectedSettingsPath =
125130 hasProxy && useSegmentEndpoints
126131 ? `/projects/${ config . writeKey } /settings`
127132 : `/${ config . writeKey } /settings` ;
128-
129- expect ( fetch ) . toHaveBeenCalledWith ( getURL ( settingsPrefix , expectedSettingsPath ) , {
130- headers : {
131- 'Cache-Control' : 'no-cache' ,
132- } ,
133- } ) ;
134-
133+
134+ expect ( fetch ) . toHaveBeenCalledWith (
135+ getURL ( settingsPrefix , expectedSettingsPath ) ,
136+ {
137+ headers : {
138+ 'Cache-Control' : 'no-cache' ,
139+ } ,
140+ }
141+ ) ;
142+
135143 // Ensure default settings are used after failure
136- expect ( setSettingsSpy ) . toHaveBeenCalledWith ( defaultIntegrationSettings . integrations ) ;
137- expect ( store . settings . get ( ) ) . toEqual ( defaultIntegrationSettings . integrations ) ;
138- expect ( client . settings . get ( ) ) . toEqual ( defaultIntegrationSettings . integrations ) ;
144+ expect ( setSettingsSpy ) . toHaveBeenCalledWith (
145+ defaultIntegrationSettings . integrations
146+ ) ;
147+ expect ( store . settings . get ( ) ) . toEqual (
148+ defaultIntegrationSettings . integrations
149+ ) ;
150+ expect ( client . settings . get ( ) ) . toEqual (
151+ defaultIntegrationSettings . integrations
152+ ) ;
139153 }
140154 ) ;
141-
155+
142156 it . each ( [
143157 [ false , false ] , // No proxy, No segment endpoint
144- [ false , true ] , // No proxy, Yes segment endpoint
145- [ true , false ] , // Yes proxy, No segment endpoint
146- [ true , true ] , // Yes proxy, Yes segment endpoint
158+ [ false , true ] , // No proxy, Yes segment endpoint
159+ [ true , false ] , // Yes proxy, No segment endpoint
160+ [ true , true ] , // Yes proxy, Yes segment endpoint
147161 ] ) (
148162 'fails to fetch settings and has no default settings when hasProxy is %s and useSegmentEndpoints is %s' ,
149163 async ( hasProxy , useSegmentEndpoints ) => {
150164 // Mock fetch to reject (simulate failure)
151165 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
152166 // @ts -ignore
153167 global . fetch = jest . fn ( ( ) => Promise . reject ( ) ) ;
154-
168+
155169 // Set up config dynamically
156170 const config = {
157171 ...clientArgs . config ,
158172 useSegmentEndpoints,
159173 cdnProxy : hasProxy ? 'https://custom-proxy.com' : undefined , // Set proxy only when true
160174 defaultSettings : undefined , // Ensure no default settings
161175 } ;
162-
176+
163177 // Create client with the dynamic config
164178 const anotherClient = new SegmentClient ( {
165179 ...clientArgs ,
166180 config,
167181 } ) ;
168-
182+
169183 await anotherClient . fetchSettings ( ) ;
170-
184+
171185 // Determine expected settings URL
172186 const settingsPrefix = config . cdnProxy ?? settingsCDN ;
173187 const expectedSettingsPath =
174188 hasProxy && useSegmentEndpoints
175189 ? `/projects/${ config . writeKey } /settings`
176190 : `/${ config . writeKey } /settings` ;
177-
178- expect ( fetch ) . toHaveBeenCalledWith ( getURL ( settingsPrefix , expectedSettingsPath ) , {
179- headers : {
180- 'Cache-Control' : 'no-cache' ,
181- } ,
182- } ) ;
183-
191+
192+ expect ( fetch ) . toHaveBeenCalledWith (
193+ getURL ( settingsPrefix , expectedSettingsPath ) ,
194+ {
195+ headers : {
196+ 'Cache-Control' : 'no-cache' ,
197+ } ,
198+ }
199+ ) ;
200+
184201 // Ensure no default settings are applied
185202 expect ( setSettingsSpy ) . not . toHaveBeenCalled ( ) ;
186203 }
187204 ) ;
188205
189206 it . each ( [
190207 [ false , false ] , // No proxy, No segment endpoint
191- [ false , true ] , // No proxy, Yes segment endpoint
192- [ true , false ] , // Yes proxy, No segment endpoint
193- [ true , true ] , // Yes proxy, Yes segment endpoint
208+ [ false , true ] , // No proxy, Yes segment endpoint
209+ [ true , false ] , // Yes proxy, No segment endpoint
210+ [ true , true ] , // Yes proxy, Yes segment endpoint
194211 ] ) (
195212 'fails to fetch settings due to soft API errors and has no default settings when hasProxy is %s and useSegmentEndpoints is %s' ,
196213 async ( hasProxy , useSegmentEndpoints ) => {
197214 const mockResponse = Promise . resolve ( {
198215 ok : false ,
199216 status : 500 , // Simulate a soft API error (server error)
200217 } ) ;
201-
218+
202219 // Mock fetch to return the error response
203220 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
204221 // @ts -ignore
205222 global . fetch = jest . fn ( ( ) => Promise . resolve ( mockResponse ) ) ;
206-
223+
207224 // Set up config dynamically
208225 const config = {
209226 ...clientArgs . config ,
210227 useSegmentEndpoints,
211228 cdnProxy : hasProxy ? 'https://custom-proxy.com' : undefined , // Set proxy only when true
212229 defaultSettings : undefined , // Ensure no default settings
213230 } ;
214-
231+
215232 // Create client with the dynamic config
216233 const anotherClient = new SegmentClient ( {
217234 ...clientArgs ,
218235 config,
219236 } ) ;
220-
237+
221238 await anotherClient . fetchSettings ( ) ;
222-
239+
223240 // Determine expected settings URL
224241 const settingsPrefix = config . cdnProxy ?? settingsCDN ;
225242 const expectedSettingsPath =
226243 hasProxy && useSegmentEndpoints
227244 ? `/projects/${ config . writeKey } /settings`
228245 : `/${ config . writeKey } /settings` ;
229-
230- expect ( fetch ) . toHaveBeenCalledWith ( getURL ( settingsPrefix , expectedSettingsPath ) , {
231- headers : {
232- 'Cache-Control' : 'no-cache' ,
233- } ,
234- } ) ;
235-
246+
247+ expect ( fetch ) . toHaveBeenCalledWith (
248+ getURL ( settingsPrefix , expectedSettingsPath ) ,
249+ {
250+ headers : {
251+ 'Cache-Control' : 'no-cache' ,
252+ } ,
253+ }
254+ ) ;
255+
236256 // Ensure no default settings are applied when API fails
237257 expect ( setSettingsSpy ) . not . toHaveBeenCalled ( ) ;
238258 }
0 commit comments