@@ -4,7 +4,9 @@ import com.onesignal.core.internal.language.ILanguageContext
4
4
import com.onesignal.mocks.MockHelper
5
5
import com.onesignal.user.internal.subscriptions.ISubscriptionManager
6
6
import com.onesignal.user.internal.subscriptions.SubscriptionList
7
+ import io.kotest.assertions.throwables.shouldNotThrow
7
8
import io.kotest.core.spec.style.FunSpec
9
+ import io.kotest.matchers.equals.shouldBeEqual
8
10
import io.kotest.matchers.shouldBe
9
11
import io.kotest.matchers.shouldNotBe
10
12
import io.mockk.every
@@ -26,7 +28,7 @@ class UserManagerTests : FunSpec({
26
28
every { languageContext.language = capture(languageSlot) } answers { }
27
29
28
30
val userManager =
29
- UserManager (mockSubscriptionManager, MockHelper .identityModelStore(), MockHelper .propertiesModelStore(), languageContext)
31
+ UserManager (mockSubscriptionManager, MockHelper .identityModelStore(), MockHelper .propertiesModelStore(), MockHelper .customEventController(), languageContext)
30
32
31
33
// When
32
34
userManager.setLanguage("new-language")
@@ -44,7 +46,7 @@ class UserManagerTests : FunSpec({
44
46
}
45
47
46
48
val userManager =
47
- UserManager (mockSubscriptionManager, identityModelStore, MockHelper .propertiesModelStore(), MockHelper .languageContext())
49
+ UserManager (mockSubscriptionManager, identityModelStore, MockHelper .propertiesModelStore(), MockHelper .customEventController(), MockHelper . languageContext())
48
50
49
51
// When
50
52
val externalId = userManager.externalId
@@ -63,7 +65,7 @@ class UserManagerTests : FunSpec({
63
65
}
64
66
65
67
val userManager =
66
- UserManager (mockSubscriptionManager, identityModelStore, MockHelper .propertiesModelStore(), MockHelper .languageContext())
68
+ UserManager (mockSubscriptionManager, identityModelStore, MockHelper .propertiesModelStore(), MockHelper .customEventController(), MockHelper . languageContext())
67
69
68
70
// When
69
71
val alias1 = userManager.aliases[" my-alias-key1" ]
@@ -102,7 +104,7 @@ class UserManagerTests : FunSpec({
102
104
}
103
105
104
106
val userManager =
105
- UserManager (mockSubscriptionManager, MockHelper .identityModelStore(), propertiesModelStore, MockHelper .languageContext())
107
+ UserManager (mockSubscriptionManager, MockHelper .identityModelStore(), propertiesModelStore, MockHelper .customEventController(), MockHelper . languageContext())
106
108
107
109
// When
108
110
val tag1 = propertiesModelStore.model.tags[" my-tag-key1" ]
@@ -141,7 +143,7 @@ class UserManagerTests : FunSpec({
141
143
it.tags[" my-tag-key1" ] = " my-tag-value1"
142
144
}
143
145
144
- val userManager = UserManager (mockSubscriptionManager, MockHelper .identityModelStore(), propertiesModelStore, MockHelper .languageContext())
146
+ val userManager = UserManager (mockSubscriptionManager, MockHelper .identityModelStore(), propertiesModelStore, MockHelper .customEventController(), MockHelper . languageContext())
145
147
146
148
// When
147
149
val tagSnapshot1 = userManager.getTags()
@@ -173,6 +175,7 @@ class UserManagerTests : FunSpec({
173
175
mockSubscriptionManager,
174
176
MockHelper .identityModelStore(),
175
177
MockHelper .propertiesModelStore(),
178
+ MockHelper .customEventController(),
176
179
MockHelper .languageContext(),
177
180
)
178
181
@@ -191,4 +194,42 @@ class UserManagerTests : FunSpec({
191
194
verify(exactly = 1) { mockSubscriptionManager.addSmsSubscription("+15558675309") }
192
195
verify(exactly = 1) { mockSubscriptionManager.removeSmsSubscription("+15558675309") }
193
196
}
197
+
198
+ test("custom event controller sends various types of properties") {
199
+ // Given
200
+ val customEventController = MockHelper .customEventController()
201
+
202
+ val userManager =
203
+ UserManager (mockk<ISubscriptionManager >(), MockHelper .identityModelStore(), MockHelper .propertiesModelStore(), customEventController, MockHelper .languageContext())
204
+
205
+ val eventName = " eventName"
206
+ val properties =
207
+ mapOf(
208
+ "key1" to "value1",
209
+ "key2" to 2,
210
+ "key3" to 5.123,
211
+ "key4" to mapOf("key4-1" to "value4-1"),
212
+ "key5" to mapOf("key5-1" to mapOf("key5-1-1" to 0)),
213
+ )
214
+
215
+ // When
216
+ // should be able to handle any of the map structures above
217
+ shouldNotThrow<Exception > {
218
+ userManager.trackEvent(
219
+ eventName,
220
+ properties,
221
+ )
222
+ }
223
+
224
+ // Then
225
+ // ensure the controller call sendCustomEvent() with the correct name and properties
226
+ verify(exactly = 1) {
227
+ customEventController.sendCustomEvent(
228
+ withArg {
229
+ it.name shouldBeEqual(eventName)
230
+ it.properties.toString() shouldBeEqual(properties.toString())
231
+ },
232
+ )
233
+ }
234
+ }
194
235
})
0 commit comments