Skip to content

Commit

Permalink
add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Nov 12, 2024
1 parent 683fad2 commit e9117df
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions posthog/src/test/java/com/posthog/PostHogTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,45 @@ internal class PostHogTest {
sut.close()
}

@Test
fun `does not capture a set event if different user`() {
val http = mockHttp()
val url = http.url("/")

val sut = getSut(url.toString(), preloadFeatureFlags = false, reloadFeatureFlags = false)

sut.identify(
DISTINCT_ID,
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
)

val userProps = mapOf("user1" to "theResult")
val userPropsOnce = mapOf("logged" to false)

sut.identify(
"different user",
userProperties = userProps,
userPropertiesSetOnce = userPropsOnce,
)

queueExecutor.shutdownAndAwaitTermination()

queueExecutor.shutdownAndAwaitTermination()

val request = http.takeRequest()

val content = request.body.unGzip()
val batch = serializer.deserialize<PostHogBatchEvent>(content.reader())

val theEvent = batch.batch.last()

assertEquals(1, batch.batch.size)
assertEquals("\$identify", theEvent.event)

sut.close()
}

@Test
fun `captures an identify event post reset`() {
val http = mockHttp()
Expand Down

0 comments on commit e9117df

Please sign in to comment.