Skip to content

Commit 1efd26f

Browse files
committed
fix unit tests
1 parent d695599 commit 1efd26f

File tree

1 file changed

+33
-38
lines changed

1 file changed

+33
-38
lines changed

core/src/test/kotlin/com/segment/analytics/kotlin/core/AnalyticsTests.kt

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,6 @@ class AsyncAnalyticsTests {
996996

997997
@BeforeEach
998998
fun setup() {
999-
clearPersistentStorage()
1000-
1001999
httpSemaphore = Semaphore(0)
10021000
assertSemaphore = Semaphore(0)
10031001

@@ -1028,14 +1026,14 @@ class AsyncAnalyticsTests {
10281026
input
10291027
}
10301028
analytics = Analytics(Configuration(writeKey = "123", application = "Test"))
1029+
analytics.add(afterPlugin)
10311030
}
10321031

10331032
@Test
10341033
fun `startup queue should replay with track enrichment closure`() {
10351034
val expectedEvent = "foo"
10361035
val expectedAnonymousId = "bar"
10371036

1038-
analytics.add(afterPlugin)
10391037
analytics.track(expectedEvent) {
10401038
it?.anonymousId = expectedAnonymousId
10411039
it
@@ -1057,39 +1055,38 @@ class AsyncAnalyticsTests {
10571055
}
10581056
}
10591057

1060-
// @Test
1061-
// fun `startup queue should replay with identify enrichment closure`() {
1062-
// val expected = buildJsonObject {
1063-
// put("foo", "baz")
1064-
// }
1065-
// val expectedUserId = "newUserId"
1066-
//
1067-
// analytics.add(afterPlugin)
1068-
// analytics.identify(expectedUserId) {
1069-
// if (it is IdentifyEvent) {
1070-
// it.traits = updateJsonObject(it.traits) {
1071-
// it["foo"] = "baz"
1072-
// }
1073-
// }
1074-
// it
1075-
// }
1076-
//
1077-
// // now we have tracked event, i.e. event added to startup queue
1078-
// // release the semaphore put on http client, so we startup queue will replay the events
1079-
// httpSemaphore.release()
1080-
// // now we need to wait for events being fully replayed before making assertions
1081-
// assertSemaphore.acquire()
1082-
//
1083-
// val actualUserId = analytics.userId()
1084-
//
1085-
// assertTrue(actual.isCaptured)
1086-
// actual.captured.let {
1087-
// assertTrue(it is IdentifyEvent)
1088-
// val e = it as IdentifyEvent
1089-
// assertEquals(expected, e.traits)
1090-
// assertEquals(expectedUserId, actualUserId)
1091-
// }
1092-
// }
1058+
@Test
1059+
fun `startup queue should replay with identify enrichment closure`() {
1060+
val expected = buildJsonObject {
1061+
put("foo", "baz")
1062+
}
1063+
val expectedUserId = "newUserId"
1064+
1065+
analytics.identify(expectedUserId) {
1066+
if (it is IdentifyEvent) {
1067+
it.traits = updateJsonObject(it.traits) {
1068+
it["foo"] = "baz"
1069+
}
1070+
}
1071+
it
1072+
}
1073+
1074+
// now we have tracked event, i.e. event added to startup queue
1075+
// release the semaphore put on http client, so we startup queue will replay the events
1076+
httpSemaphore.release()
1077+
// now we need to wait for events being fully replayed before making assertions
1078+
assertSemaphore.acquire()
1079+
1080+
val actualUserId = analytics.userId()
1081+
1082+
assertTrue(actual.isCaptured)
1083+
actual.captured.let {
1084+
assertTrue(it is IdentifyEvent)
1085+
val e = it as IdentifyEvent
1086+
assertEquals(expected, e.traits)
1087+
assertEquals(expectedUserId, actualUserId)
1088+
}
1089+
}
10931090

10941091
@Test
10951092
fun `startup queue should replay with group enrichment closure`() {
@@ -1098,7 +1095,6 @@ class AsyncAnalyticsTests {
10981095
}
10991096
val expectedGroupId = "foo"
11001097

1101-
analytics.add(afterPlugin)
11021098
analytics.group(expectedGroupId) {
11031099
if (it is GroupEvent) {
11041100
it.traits = updateJsonObject(it.traits) {
@@ -1127,7 +1123,6 @@ class AsyncAnalyticsTests {
11271123
fun `startup queue should replay with alias enrichment closure`() {
11281124
val expected = "bar"
11291125

1130-
analytics.add(afterPlugin)
11311126
analytics.alias(expected) {
11321127
it?.anonymousId = "test"
11331128
it

0 commit comments

Comments
 (0)