1
- package com.segment.analytics.kotlin.destinations.plugins
1
+ package com.segment.analytics.kotlin.destinations.mixpanel
2
2
3
3
import android.content.Context
4
4
import com.mixpanel.android.mpmetrics.MixpanelAPI
5
5
import com.segment.analytics.kotlin.core.*
6
6
import com.segment.analytics.kotlin.core.platform.Plugin
7
+ import com.segment.analytics.kotlin.destinations.mixpanel.MixpanelDestination
8
+ import com.segment.analytics.kotlin.destinations.mixpanel.MixpanelSettings
7
9
import io.mockk.*
8
10
import io.mockk.impl.annotations.MockK
9
11
import kotlinx.serialization.decodeFromString
@@ -12,12 +14,11 @@ import kotlinx.serialization.json.buildJsonObject
12
14
import kotlinx.serialization.json.put
13
15
import org.json.JSONException
14
16
import org.json.JSONObject
15
- import org.junit.jupiter.api.Assertions.*
17
+ import org.junit.jupiter.api.Assertions
16
18
import org.junit.jupiter.api.Test
17
19
import org.skyscreamer.jsonassert.JSONAssert
18
20
import org.skyscreamer.jsonassert.JSONCompareMode
19
21
20
-
21
22
class MixpanelDestinationTests {
22
23
23
24
private val mockContext = mockk<Context >(relaxed = true )
@@ -81,20 +82,23 @@ class MixpanelDestinationTests {
81
82
mixpanelDestination.update(settingsBlob, Plugin .UpdateType .Initial )
82
83
83
84
/* assertions about config */
84
- assertNotNull(mixpanelDestination.settings)
85
+ Assertions . assertNotNull(mixpanelDestination.settings)
85
86
with (mixpanelDestination.settings!! ) {
86
- assertFalse(consolidatedPageCalls)
87
- assertTrue(isPeopleEnabled)
88
- assertFalse(trackAllPages)
89
- assertTrue(trackCategorizedPages)
90
- assertFalse(trackNamedPages)
91
- assertFalse(setAllTraitsByDefault)
87
+ Assertions . assertFalse(consolidatedPageCalls)
88
+ Assertions . assertTrue(isPeopleEnabled)
89
+ Assertions . assertFalse(trackAllPages)
90
+ Assertions . assertTrue(trackCategorizedPages)
91
+ Assertions . assertFalse(trackNamedPages)
92
+ Assertions . assertFalse(setAllTraitsByDefault)
92
93
93
- assertEquals(" token1234" , token)
94
+ Assertions . assertEquals(" token1234" , token)
94
95
95
- assertEquals(emptySet<String >(), superPropertiesFilter)
96
- assertEquals(setOf (" email" , " username" , " phone_number" ), peoplePropertiesFilter)
97
- assertEquals(setOf (" Product Clicked" , " Product Viewed" ), increments)
96
+ Assertions .assertEquals(emptySet<String >(), superPropertiesFilter)
97
+ Assertions .assertEquals(
98
+ setOf (" email" , " username" , " phone_number" ),
99
+ peoplePropertiesFilter
100
+ )
101
+ Assertions .assertEquals(setOf (" Product Clicked" , " Product Viewed" ), increments)
98
102
}
99
103
}
100
104
@@ -125,7 +129,7 @@ class MixpanelDestinationTests {
125
129
)
126
130
val screenEvent = mixpanelDestination.screen(sampleEvent)
127
131
128
- assertNotNull(screenEvent)
132
+ Assertions . assertNotNull(screenEvent)
129
133
verify { mockMixpanel wasNot Called }
130
134
}
131
135
@@ -154,7 +158,7 @@ class MixpanelDestinationTests {
154
158
)
155
159
val screenEvent = mixpanelDestination.screen(sampleEvent)
156
160
157
- assertNotNull(screenEvent)
161
+ Assertions . assertNotNull(screenEvent)
158
162
verify {
159
163
mockMixpanel.track(
160
164
" Viewed LoginFragment Screen" ,
@@ -192,7 +196,7 @@ class MixpanelDestinationTests {
192
196
)
193
197
val screenEvent = mixpanelDestination.screen(sampleEvent)
194
198
195
- assertNotNull(screenEvent)
199
+ Assertions . assertNotNull(screenEvent)
196
200
verify {
197
201
mockMixpanel.track(
198
202
" Loaded a Screen" ,
@@ -232,7 +236,7 @@ class MixpanelDestinationTests {
232
236
)
233
237
val screenEvent = mixpanelDestination.screen(sampleEvent)
234
238
235
- assertNotNull(screenEvent)
239
+ Assertions . assertNotNull(screenEvent)
236
240
verify {
237
241
mockMixpanel.track(
238
242
" Viewed LoginFragment Screen" ,
@@ -271,7 +275,7 @@ class MixpanelDestinationTests {
271
275
)
272
276
val screenEvent = mixpanelDestination.screen(sampleEvent)
273
277
274
- assertNotNull(screenEvent)
278
+ Assertions . assertNotNull(screenEvent)
275
279
verify { mockMixpanel wasNot Called }
276
280
}
277
281
@@ -301,7 +305,7 @@ class MixpanelDestinationTests {
301
305
)
302
306
val screenEvent = mixpanelDestination.screen(sampleEvent)
303
307
304
- assertNotNull(screenEvent)
308
+ Assertions . assertNotNull(screenEvent)
305
309
verify {
306
310
mockMixpanel.track(
307
311
" Viewed signup_flow Screen" ,
@@ -340,7 +344,7 @@ class MixpanelDestinationTests {
340
344
)
341
345
val screenEvent = mixpanelDestination.screen(sampleEvent)
342
346
343
- assertNotNull(screenEvent)
347
+ Assertions . assertNotNull(screenEvent)
344
348
verify { mockMixpanel wasNot Called }
345
349
}
346
350
@@ -364,7 +368,7 @@ class MixpanelDestinationTests {
364
368
val trackEvent = mixpanelDestination.track(sampleEvent)
365
369
366
370
367
- assertNotNull(trackEvent)
371
+ Assertions . assertNotNull(trackEvent)
368
372
369
373
verify {
370
374
mockMixpanel.track(
@@ -399,7 +403,7 @@ class MixpanelDestinationTests {
399
403
val trackEvent = mixpanelDestination.track(sampleEvent)
400
404
401
405
402
- assertNotNull(trackEvent)
406
+ Assertions . assertNotNull(trackEvent)
403
407
404
408
verify {
405
409
mockMixpanel.track(
@@ -442,7 +446,7 @@ class MixpanelDestinationTests {
442
446
val trackEvent = mixpanelDestination.track(sampleEvent)
443
447
444
448
445
- assertNotNull(trackEvent)
449
+ Assertions . assertNotNull(trackEvent)
446
450
447
451
verify {
448
452
mockMixpanel.track(
@@ -479,7 +483,7 @@ class MixpanelDestinationTests {
479
483
val trackEvent = mixpanelDestination.alias(sampleEvent)
480
484
481
485
482
- assertNotNull(trackEvent)
486
+ Assertions . assertNotNull(trackEvent)
483
487
484
488
verify {
485
489
mockMixpanel.alias(
@@ -511,7 +515,7 @@ class MixpanelDestinationTests {
511
515
val trackEvent = mixpanelDestination.alias(sampleEvent)
512
516
513
517
514
- assertNotNull(trackEvent)
518
+ Assertions . assertNotNull(trackEvent)
515
519
516
520
verify {
517
521
mockMixpanel.alias(
@@ -540,7 +544,7 @@ class MixpanelDestinationTests {
540
544
)
541
545
val identifyEvent = mixpanelDestination.identify(sampleEvent)
542
546
543
- assertNotNull(identifyEvent)
547
+ Assertions . assertNotNull(identifyEvent)
544
548
545
549
verify { mockMixpanel.identify(" abc-123" ) }
546
550
verify {
@@ -571,7 +575,7 @@ class MixpanelDestinationTests {
571
575
)
572
576
val identifyEvent = mixpanelDestination.identify(sampleEvent)
573
577
574
- assertNotNull(identifyEvent)
578
+ Assertions . assertNotNull(identifyEvent)
575
579
576
580
verify(exactly = 0 ) { mockMixpanel.identify(" abc-123" ) }
577
581
verify {
@@ -603,7 +607,7 @@ class MixpanelDestinationTests {
603
607
)
604
608
val identifyEvent = mixpanelDestination.identify(sampleEvent)
605
609
606
- assertNotNull(identifyEvent)
610
+ Assertions . assertNotNull(identifyEvent)
607
611
608
612
verify { mockMixpanel.identify(" abc-123" ) }
609
613
verify {
@@ -650,7 +654,7 @@ class MixpanelDestinationTests {
650
654
)
651
655
val identifyEvent = mixpanelDestination.identify(sampleEvent)
652
656
653
- assertNotNull(identifyEvent)
657
+ Assertions . assertNotNull(identifyEvent)
654
658
655
659
val expectedTraits = JSONObject ()
656
660
.put(" \$ email" , " 123@abc.com" )
@@ -701,7 +705,7 @@ class MixpanelDestinationTests {
701
705
)
702
706
val identifyEvent = mixpanelDestination.identify(sampleEvent)
703
707
704
- assertNotNull(identifyEvent)
708
+ Assertions . assertNotNull(identifyEvent)
705
709
706
710
val expectedTraits = JSONObject ()
707
711
.put(" \$ phone" , " 987-654-3210" )
@@ -747,7 +751,7 @@ class MixpanelDestinationTests {
747
751
)
748
752
val identifyEvent = mixpanelDestination.identify(sampleEvent)
749
753
750
- assertNotNull(identifyEvent)
754
+ Assertions . assertNotNull(identifyEvent)
751
755
752
756
val expectedTraits = JSONObject ()
753
757
.put(" \$ phone" , " 987-654-3210" )
@@ -787,7 +791,7 @@ class MixpanelDestinationTests {
787
791
)
788
792
val groupEvent = mixpanelDestination.group(sampleEvent)
789
793
790
- assertNotNull(groupEvent)
794
+ Assertions . assertNotNull(groupEvent)
791
795
792
796
// check mixpanel getGroup called with groupKey default "[Segment] Group" and groupID "grp-123"
793
797
verify { mockMixpanel.getGroup(" [Segment] Group" , " grp-123" ) }
@@ -828,7 +832,7 @@ class MixpanelDestinationTests {
828
832
)
829
833
val groupEvent = mixpanelDestination.group(sampleEvent)
830
834
831
- assertNotNull(groupEvent)
835
+ Assertions . assertNotNull(groupEvent)
832
836
833
837
// check mixpanel getGroup called with groupKey default "ABC network" and groupID "grp-123"
834
838
verify { mockMixpanel.getGroup(" ABC network" , " grp-123" ) }
0 commit comments