Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Oct 14, 2024
1 parent 1b49526 commit 130d39a
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,96 @@ internal class PostHogFeatureFlagsTest {
assertTrue(sut.isSessionReplayFlagActive())
assertEquals("/b/", config?.snapshotEndpoint)
}

@Test
fun `returns isSessionReplayFlagActive true if bool linked flag is enabled`() {
val file = File("src/test/resources/json/basic-decide-recording-bool-linked-enabled.json")

val http =
mockHttp(
response =
MockResponse()
.setBody(file.readText()),
)
val url = http.url("/")

val sut = getSut(host = url.toString())

sut.loadFeatureFlags("my_identify", anonymousId = "anonId", emptyMap(), null)

executor.shutdownAndAwaitTermination()

assertTrue(sut.isSessionReplayFlagActive())

sut.clear()
}

@Test
fun `returns isSessionReplayFlagActive false if bool linked flag is disabled`() {
val file = File("src/test/resources/json/basic-decide-recording-bool-linked-disabled.json")

val http =
mockHttp(
response =
MockResponse()
.setBody(file.readText()),
)
val url = http.url("/")

val sut = getSut(host = url.toString())

sut.loadFeatureFlags("my_identify", anonymousId = "anonId", emptyMap(), null)

executor.shutdownAndAwaitTermination()

assertFalse(sut.isSessionReplayFlagActive())

sut.clear()
}

@Test
fun `returns isSessionReplayFlagActive true if multi variant linked flag is a match`() {
val file = File("src/test/resources/json/basic-decide-recording-bool-linked-variant-match.json")

val http =
mockHttp(
response =
MockResponse()
.setBody(file.readText()),
)
val url = http.url("/")

val sut = getSut(host = url.toString())

sut.loadFeatureFlags("my_identify", anonymousId = "anonId", emptyMap(), null)

executor.shutdownAndAwaitTermination()

assertTrue(sut.isSessionReplayFlagActive())

sut.clear()
}

@Test
fun `returns isSessionReplayFlagActive false if multi variant linked flag is not a match`() {
val file = File("src/test/resources/json/basic-decide-recording-bool-linked-variant-not-match.json")

val http =
mockHttp(
response =
MockResponse()
.setBody(file.readText()),
)
val url = http.url("/")

val sut = getSut(host = url.toString())

sut.loadFeatureFlags("my_identify", anonymousId = "anonId", emptyMap(), null)

executor.shutdownAndAwaitTermination()

assertFalse(sut.isSessionReplayFlagActive())

sut.clear()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"autocaptureExceptions": false,
"toolbarParams": {},
"errorsWhileComputingFlags": false,
"capturePerformance": true,
"autocapture_opt_out": false,
"isAuthenticated": false,
"supportedCompression": [
"gzip",
"gzip-js"
],
"config": {
"enable_collect_everything": true
},
"featureFlagPayloads": {
"thePayload": true
},
"featureFlags": {
"4535-funnel-bar-viz": true,
"session-replay-flag": false
},
"sessionRecording": {
"endpoint": "/b/",
"linkedFlag": "session-replay-flag"
},
"siteApps": [
{
"id": 21039.0,
"url": "/site_app/21039/EOsOSePYNyTzHkZ3f4mjrjUap8Hy8o2vUTAc6v1ZMFP/576ac89bc8aed72a21d9b19221c2c626/"
}
],
"editorParams": {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"autocaptureExceptions": false,
"toolbarParams": {},
"errorsWhileComputingFlags": false,
"capturePerformance": true,
"autocapture_opt_out": false,
"isAuthenticated": false,
"supportedCompression": [
"gzip",
"gzip-js"
],
"config": {
"enable_collect_everything": true
},
"featureFlagPayloads": {
"thePayload": true
},
"featureFlags": {
"4535-funnel-bar-viz": true,
"session-replay-flag": true
},
"sessionRecording": {
"endpoint": "/b/",
"linkedFlag": "session-replay-flag"
},
"siteApps": [
{
"id": 21039.0,
"url": "/site_app/21039/EOsOSePYNyTzHkZ3f4mjrjUap8Hy8o2vUTAc6v1ZMFP/576ac89bc8aed72a21d9b19221c2c626/"
}
],
"editorParams": {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"autocaptureExceptions": false,
"toolbarParams": {},
"errorsWhileComputingFlags": false,
"capturePerformance": true,
"autocapture_opt_out": false,
"isAuthenticated": false,
"supportedCompression": [
"gzip",
"gzip-js"
],
"config": {
"enable_collect_everything": true
},
"featureFlagPayloads": {
"thePayload": true
},
"featureFlags": {
"4535-funnel-bar-viz": true,
"session-replay-flag": "variant-1"
},
"sessionRecording": {
"endpoint": "/b/",
"linkedFlag": {
"flag": "session-replay-flag",
"variant": "variant-1"
}
},
"siteApps": [
{
"id": 21039.0,
"url": "/site_app/21039/EOsOSePYNyTzHkZ3f4mjrjUap8Hy8o2vUTAc6v1ZMFP/576ac89bc8aed72a21d9b19221c2c626/"
}
],
"editorParams": {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"autocaptureExceptions": false,
"toolbarParams": {},
"errorsWhileComputingFlags": false,
"capturePerformance": true,
"autocapture_opt_out": false,
"isAuthenticated": false,
"supportedCompression": [
"gzip",
"gzip-js"
],
"config": {
"enable_collect_everything": true
},
"featureFlagPayloads": {
"thePayload": true
},
"featureFlags": {
"4535-funnel-bar-viz": true,
"session-replay-flag": "variant-2"
},
"sessionRecording": {
"endpoint": "/b/",
"linkedFlag": {
"flag": "session-replay-flag",
"variant": "variant-1"
}
},
"siteApps": [
{
"id": 21039.0,
"url": "/site_app/21039/EOsOSePYNyTzHkZ3f4mjrjUap8Hy8o2vUTAc6v1ZMFP/576ac89bc8aed72a21d9b19221c2c626/"
}
],
"editorParams": {

}
}

0 comments on commit 130d39a

Please sign in to comment.