-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from Flagsmith/feat/support-transient-identiti…
…es-and-traits feat: support transient identities and traits
- Loading branch information
Showing
11 changed files
with
264 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
FlagsmithClient/src/test/java/com/flagsmith/IdentityTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.flagsmith | ||
|
||
import com.flagsmith.entities.Trait | ||
import com.flagsmith.mockResponses.MockEndpoint | ||
import com.flagsmith.mockResponses.MockResponses | ||
import com.flagsmith.mockResponses.mockResponseFor | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.mockserver.integration.ClientAndServer | ||
import org.mockserver.model.HttpRequest.request | ||
|
||
class IdentityTests { | ||
|
||
private lateinit var mockServer: ClientAndServer | ||
private lateinit var flagsmith: Flagsmith | ||
|
||
@Before | ||
fun setup() { | ||
mockServer = ClientAndServer.startClientAndServer() | ||
flagsmith = Flagsmith( | ||
environmentKey = "", | ||
baseUrl = "http://localhost:${mockServer.localPort}", | ||
enableAnalytics = false, | ||
cacheConfig = FlagsmithCacheConfig(enableCache = false) | ||
) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
mockServer.stop() | ||
} | ||
|
||
@Test | ||
fun testGetIdentity() { | ||
mockServer.mockResponseFor(MockEndpoint.GET_IDENTITIES) | ||
runBlocking { | ||
val result = flagsmith.getIdentitySync("person") | ||
|
||
mockServer.verify( | ||
request() | ||
.withPath("/identities/") | ||
.withMethod("GET") | ||
.withQueryStringParameter("identifier", "person") | ||
) | ||
|
||
assertTrue(result.isSuccess) | ||
assertTrue(result.getOrThrow().traits.isNotEmpty()) | ||
assertTrue(result.getOrThrow().flags.isNotEmpty()) | ||
assertEquals( | ||
"electric pink", | ||
result.getOrThrow().traits.find { trait -> trait.key == "favourite-colour" }?.stringValue | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun testGetTransientIdentity() { | ||
mockServer.mockResponseFor(MockEndpoint.GET_TRANSIENT_IDENTITIES) | ||
runBlocking { | ||
val result = flagsmith.getIdentitySync("transient-identity", true) | ||
|
||
mockServer.verify( | ||
request() | ||
.withPath("/identities/") | ||
.withMethod("GET") | ||
.withQueryStringParameter("identifier", "transient-identity") | ||
.withQueryStringParameter("transient", "true") | ||
) | ||
|
||
assertTrue(result.isSuccess) | ||
assertTrue(result.getOrThrow().traits.isEmpty()) | ||
assertTrue(result.getOrThrow().flags.isNotEmpty()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.