Skip to content

Commit

Permalink
Move identity tests to their own test file
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell committed Oct 4, 2024
1 parent 61af2ed commit 0a8433c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 31 deletions.
66 changes: 66 additions & 0 deletions FlagsmithClient/src/test/java/com/flagsmith/IdentityTests.kt
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())
}
}
}
31 changes: 0 additions & 31 deletions FlagsmithClient/src/test/java/com/flagsmith/TraitsTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,35 +168,4 @@ class TraitsTests {
assertEquals("person", result.getOrThrow().identity.identifier)
}
}

@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())
}
}
}

0 comments on commit 0a8433c

Please sign in to comment.