-
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.
Move identity tests to their own test file
- Loading branch information
1 parent
61af2ed
commit 0a8433c
Showing
2 changed files
with
66 additions
and
31 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
package com.flagsmith | ||
|
||
import com.flagsmith.entities.Trait | ||
import com.flagsmith.mockResponses.MockEndpoint | ||
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 | ||
|
||
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") | ||
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) | ||
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 | ||
) | ||
assertEquals(true, 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