Skip to content

Commit

Permalink
fix: fix group call (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingzhuozhen authored Jun 27, 2022
1 parent 5c1e573 commit f84d143
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
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

0 comments on commit f84d143

Please sign in to comment.