@@ -88,7 +88,9 @@ class SettingsTests {
88
88
89
89
// no settings available, should not be called
90
90
analytics.add(mockPlugin)
91
-
91
+ verify (exactly = 0 ){
92
+ mockPlugin.update(any(), any())
93
+ }
92
94
93
95
// load settings
94
96
mockHTTPClient()
@@ -102,7 +104,7 @@ class SettingsTests {
102
104
// load settings again
103
105
mockHTTPClient()
104
106
analytics.checkSettings()
105
- verify (exactly = 2 ) {
107
+ verify (exactly = 1 ) {
106
108
mockPlugin.update(any(), Plugin .UpdateType .Refresh )
107
109
}
108
110
}
@@ -230,102 +232,95 @@ class SettingsTests {
230
232
231
233
@Test
232
234
fun `fetchSettings returns null when Settings string is invalid` () {
233
- val emptySettings = analytics.fetchSettings(" emptySettingsObject" , " cdn-settings.segment.com/v1" )
234
235
// Null on invalid JSON
235
236
mockHTTPClient(" " )
236
237
var settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
237
- assertEquals(emptySettings, settings)
238
+ assertNull( settings)
238
239
239
240
// Null on invalid JSON
240
241
mockHTTPClient(" hello" )
241
242
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
242
- assertEquals(emptySettings, settings)
243
+ assertNull( settings)
243
244
244
245
// Null on invalid JSON
245
246
mockHTTPClient(" #! /bin/sh" )
246
247
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
247
- assertEquals(emptySettings, settings)
248
+ assertNull( settings)
248
249
249
250
// Null on invalid JSON
250
251
mockHTTPClient(" <!DOCTYPE html>" )
251
252
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
252
- assertEquals(emptySettings, settings)
253
+ assertNull( settings)
253
254
254
255
// Null on invalid JSON
255
256
mockHTTPClient(" true" )
256
257
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
257
- assertEquals(emptySettings, settings)
258
+ assertNull( settings)
258
259
259
260
// Null on invalid JSON
260
261
mockHTTPClient(" []" )
261
262
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
262
- assertEquals(emptySettings, settings)
263
+ assertNull( settings)
263
264
264
265
// Null on invalid JSON
265
266
mockHTTPClient(" }{" )
266
267
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
267
- assertEquals(emptySettings, settings)
268
+ assertNull( settings)
268
269
269
270
// Null on invalid JSON
270
271
mockHTTPClient(" {{{{}}}}" )
271
272
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
272
- assertEquals(emptySettings, settings)
273
+ assertNull( settings)
273
274
274
275
// Null on invalid JSON
275
276
mockHTTPClient(" {null:\" bar\" }" )
276
277
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
277
- assertEquals(emptySettings, settings)
278
+ assertNull( settings)
278
279
}
279
280
280
281
@Test
281
282
fun `fetchSettings returns null when parameters are invalid` () {
282
- val emptySettings = analytics.fetchSettings(" emptySettingsObject" , " cdn-settings.segment.com/v1" )
283
283
mockHTTPClient(" {\" integrations\" :{}, \" plan\" :{}, \" edgeFunction\" : {}, \" middlewareSettings\" : {}}" )
284
284
285
285
// empty host
286
286
var settings = analytics.fetchSettings(" foo" , " " )
287
- assertEquals(emptySettings, settings)
287
+ assertNull( settings)
288
288
289
289
// not a host name
290
290
settings = analytics.fetchSettings(" foo" , " http://blah" )
291
- assertEquals(emptySettings, settings)
291
+ assertNull( settings)
292
292
293
293
// emoji
294
294
settings = analytics.fetchSettings(" foo" , " 😃" )
295
- assertEquals(emptySettings, settings)
295
+ assertNull( settings)
296
296
}
297
297
298
298
@Test
299
299
fun `fetchSettings returns null when Settings string is null for known properties` () {
300
300
// Null if integrations is null
301
301
mockHTTPClient(" {\" integrations\" :null}" )
302
302
var settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
303
- assertTrue(settings?.integrations?.isEmpty() ? : true , " Integrations should be empty" )
304
- assertTrue(settings?.plan?.isEmpty() ? : true , " Plan should be empty" )
305
- assertTrue(settings?.edgeFunction?.isEmpty() ? : true , " EdgeFunction should be empty" )
306
- assertTrue(settings?.middlewareSettings?.isEmpty() ? : true , " MiddlewareSettings should be empty" )
307
- assertTrue(settings?.metrics?.isEmpty() ? : true , " Metrics should be empty" )
308
- assertTrue(settings?.consentSettings?.isEmpty() ? : true , " ConsentSettings should be empty" )
309
-
310
- // // Null if plan is null
311
- // mockHTTPClient("{\"plan\":null}")
312
- // settings = analytics.fetchSettings("foo", "cdn-settings.segment.com/v1")
313
- // assertNull(settings)
314
- //
315
- // // Null if edgeFunction is null
316
- // mockHTTPClient("{\"edgeFunction\":null}")
317
- // settings = analytics.fetchSettings("foo", "cdn-settings.segment.com/v1")
318
- // assertNull(settings)
319
- //
320
- // // Null if middlewareSettings is null
321
- // mockHTTPClient("{\"middlewareSettings\":null}")
322
- // settings = analytics.fetchSettings("foo", "cdn-settings.segment.com/v1")
323
- // assertNull(settings)
303
+ assertNull(settings)
304
+
305
+ // Null if plan is null
306
+ mockHTTPClient(" {\" plan\" :null}" )
307
+ settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
308
+ assertNull(settings)
309
+
310
+ // Null if edgeFunction is null
311
+ mockHTTPClient(" {\" edgeFunction\" :null}" )
312
+ settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
313
+ assertNull(settings)
314
+
315
+ // Null if middlewareSettings is null
316
+ mockHTTPClient(" {\" middlewareSettings\" :null}" )
317
+ settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
318
+ assertNull(settings)
324
319
}
325
320
326
321
@Test
327
322
fun `known Settings property types must match json type` () {
328
- val emptySettings = analytics.fetchSettings( " emptySettingsObject " , " cdn-settings.segment.com/v1 " )
323
+
329
324
// integrations must be a JSON object
330
325
mockHTTPClient(" {\" integrations\" :{}}" )
331
326
var settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
@@ -334,21 +329,21 @@ class SettingsTests {
334
329
// Null if integrations is a number
335
330
mockHTTPClient(" {\" integrations\" :123}" )
336
331
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
337
- assertEquals(emptySettings, settings)
332
+ assertNull( settings)
338
333
339
334
// Null if integrations is a string
340
335
mockHTTPClient(" {\" integrations\" :\" foo\" }" )
341
336
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
342
- assertEquals(emptySettings, settings)
337
+ assertNull( settings)
343
338
344
339
// Null if integrations is an array
345
340
mockHTTPClient(" {\" integrations\" :[\" foo\" ]}" )
346
341
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
347
- assertEquals(emptySettings, settings)
342
+ assertNull( settings)
348
343
349
344
// Null if integrations is an emoji (UTF-8 string)
350
345
mockHTTPClient(" {\" integrations\" : 😃}" )
351
346
settings = analytics.fetchSettings(" foo" , " cdn-settings.segment.com/v1" )
352
- assertEquals(emptySettings, settings)
347
+ assertNull( settings)
353
348
}
354
349
}
0 commit comments