Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix group call #42

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions core/src/main/java/com/amplitude/core/Amplitude.kt
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,10 @@ open class Amplitude internal constructor(
*/
@JvmOverloads
fun setGroup(groupType: String, groupName: String, options: EventOptions? = null): Amplitude {
val identify = Identify().set(groupType, groupName)
identify(identify, options)
val event = IdentifyEvent().apply {
groups = mutableMapOf(groupType to groupName)
}
track(event, options)
return this
}

Expand All @@ -245,8 +247,10 @@ open class Amplitude internal constructor(
*/
@JvmOverloads
fun setGroup(groupType: String, groupName: Array<String>, options: EventOptions? = null): Amplitude {
val identify = Identify().set(groupType, groupName)
identify(identify, options)
val event = IdentifyEvent().apply {
groups = mutableMapOf(groupType to groupName)
}
track(event, options)
return this
}

Expand Down
10 changes: 4 additions & 6 deletions core/src/test/kotlin/com/amplitude/core/AmplitudeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,13 @@ internal class AmplitudeTest {
amplitude.setGroup("test", "groupName", eventOptions)
val identifyEvent = slot<IdentifyEvent>()
verify { mockPlugin.identify(capture(identifyEvent)) }
val expectedUserProperties = mutableMapOf<String, Any>()
expectedUserProperties[IdentifyOperation.SET.operationType] = mapOf(Pair("test", "groupName"))
val expectedGroups = mutableMapOf("test" to "groupName")
identifyEvent.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(expectedUserProperties, it.userProperties)
assertEquals(expectedGroups, it.groups)
}
}

Expand All @@ -178,14 +177,13 @@ internal class AmplitudeTest {
amplitude.setGroup("test", groups, eventOptions)
val identifyEvent = slot<IdentifyEvent>()
verify { mockPlugin.identify(capture(identifyEvent)) }
val expectedUserProperties = mutableMapOf<String, Any>()
expectedUserProperties[IdentifyOperation.SET.operationType] = mapOf(Pair("test", groups))
val expectedGroups = mutableMapOf("test" to groups)
identifyEvent.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(expectedUserProperties, it.userProperties)
assertEquals(expectedGroups, it.groups)
}
}
}
Expand Down