diff --git a/posthog/src/test/java/com/posthog/internal/PostHogFeatureFlagsTest.kt b/posthog/src/test/java/com/posthog/internal/PostHogFeatureFlagsTest.kt index 5d96bc8d..12e5341f 100644 --- a/posthog/src/test/java/com/posthog/internal/PostHogFeatureFlagsTest.kt +++ b/posthog/src/test/java/com/posthog/internal/PostHogFeatureFlagsTest.kt @@ -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() + } } diff --git a/posthog/src/test/resources/json/basic-decide-recording-bool-linked-disabled.json b/posthog/src/test/resources/json/basic-decide-recording-bool-linked-disabled.json new file mode 100644 index 00000000..66514cb3 --- /dev/null +++ b/posthog/src/test/resources/json/basic-decide-recording-bool-linked-disabled.json @@ -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": { + + } +} diff --git a/posthog/src/test/resources/json/basic-decide-recording-bool-linked-enabled.json b/posthog/src/test/resources/json/basic-decide-recording-bool-linked-enabled.json new file mode 100644 index 00000000..5bd8e4e4 --- /dev/null +++ b/posthog/src/test/resources/json/basic-decide-recording-bool-linked-enabled.json @@ -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": { + + } +} diff --git a/posthog/src/test/resources/json/basic-decide-recording-bool-linked-variant-match.json b/posthog/src/test/resources/json/basic-decide-recording-bool-linked-variant-match.json new file mode 100644 index 00000000..79bc074a --- /dev/null +++ b/posthog/src/test/resources/json/basic-decide-recording-bool-linked-variant-match.json @@ -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": { + + } +} diff --git a/posthog/src/test/resources/json/basic-decide-recording-bool-linked-variant-not-match.json b/posthog/src/test/resources/json/basic-decide-recording-bool-linked-variant-not-match.json new file mode 100644 index 00000000..142de337 --- /dev/null +++ b/posthog/src/test/resources/json/basic-decide-recording-bool-linked-variant-not-match.json @@ -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": { + + } +}