Skip to content

Commit

Permalink
feat: enable to pass the event options for all track call (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhao900914 authored Jun 1, 2022
1 parent d84a84e commit 8dd1ab6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/src/main/java/com/amplitude/core/Amplitude.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ open class Amplitude internal constructor(
*
* @param event the event
* @param callback the optional event callback
* @param options optional event options
* @return the Amplitude instance
*/
@JvmOverloads
fun track(event: BaseEvent, callback: EventCallBack? = null): Amplitude {
fun track(event: BaseEvent, options: EventOptions? = null, callback: EventCallBack? = null): Amplitude {
options ?. let {
event.mergeEventOptions(it)
}
callback ?. let {
event.callback = it
}
Expand Down
24 changes: 24 additions & 0 deletions core/src/test/kotlin/com/amplitude/core/AmplitudeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ internal class AmplitudeTest {
assertEquals("test", it.plan?.source)
}
}

@Test
fun `test track with event object and event options`() {
val mockPlugin = spyk(StubPlugin())
amplitude.add(mockPlugin)
amplitude.setUserId("user_id")
amplitude.setDeviceId("device_id")
val eventOptions = EventOptions()
eventOptions.city = "SF"
val event = BaseEvent()
event.eventType = "test event"
event.region = "CA"
amplitude.track(event, eventOptions)
val track = slot<BaseEvent>()
verify { mockPlugin.track(capture(track)) }
track.captured.let {
assertEquals("user_id", it.userId)
assertEquals("device_id", it.deviceId)
assertEquals("${Constants.SDK_LIBRARY}/${Constants.SDK_VERSION}", it.library)
assertEquals("CA", it.region)
assertEquals("SF", it.city)
assertEquals("test", it.plan?.source)
}
}
}

@Nested
Expand Down

0 comments on commit 8dd1ab6

Please sign in to comment.