Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura Warr committed Jul 12, 2023
1 parent d5cbac5 commit 139805a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run build with Gradle Wrapper
run: ./gradlew build
run: ./gradlew build --debug
# Execute unit tests
- name: Unit Test
run: ./gradlew testDebugUnitTest
run: ./gradlew testDebugUnitTest --debug
- name: Android Test Report
uses: asadmansr/android-test-report-action@v1.2.0
if: ${{ always() }} # IMPORTANT: run Android Test Report regardless
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,11 @@ class DVCClientTests {
}
}

client.identifyUser(DVCUser.builder().withUserId("new_userid").build(), callback)
client.identifyUser(DVCUser.builder().withUserId("new_userid1").build(), callback)
client.identifyUser(DVCUser.builder().withUserId("new_userid2").build(), callback)
client.identifyUser(DVCUser.builder().withUserId("new_userid3").build(), callback)
client.identifyUser(DVCUser.builder().withUserId("new_userid4").build(), callback)
client.identifyUser(DVCUser.builder().withUserId("new_userid5").build(), callback)
client.identifyUser(DVCUser.builder().withUserId("expected_userid1").build(), callback)
client.identifyUser(DVCUser.builder().withUserId("random_user1").build(), callback)
client.identifyUser(DVCUser.builder().withUserId("random_user2").build(), callback)
client.identifyUser(DVCUser.builder().withUserId("random_user3").build(), callback)
client.identifyUser(DVCUser.builder().withUserId("expected_userid2").build(), callback)

waitForOpenLatch(callbackLatch, 5000, TimeUnit.MILLISECONDS)

Expand All @@ -328,9 +327,8 @@ class DVCClientTests {
} else {
// expect only the first and last user id to be sent as a result of the identify calls
try {
Assertions.assertTrue(it.path?.contains("new_userid5") == true ||
it.path?.contains("new_userid&") == true
)
println("--- PATH: " + it.path)
Assertions.assertEquals(true, it.path?.contains("expected_userid"))
} catch (e: org.opentest4j.AssertionFailedError) {
println(it.path)
throw e
Expand Down Expand Up @@ -406,6 +404,14 @@ class DVCClientTests {
countDownLatch.countDown()
}
})
client.onInitialized(object: DVCCallback<String> {
override fun onSuccess(result: String) {
client.identifyUser(DVCUser.builder().withUserId("asdasdas").build())
}
override fun onError(t: Throwable) {
error = t
}
})
} catch(t: Throwable) {
countDownLatch.countDown()
} finally {
Expand All @@ -430,6 +436,15 @@ class DVCClientTests {
calledBack = true
countDownLatch.countDown()
}

client.onInitialized(object: DVCCallback<String> {
override fun onSuccess(result: String) {
client.identifyUser(DVCUser.builder().withUserId("asdasdas").build())
}
override fun onError(t: Throwable) {
error = t
}
})
} catch(t: Throwable) {
countDownLatch.countDown()
} finally {
Expand All @@ -441,7 +456,7 @@ class DVCClientTests {

@Test
fun `variable calls back when variable value has changed for json object`() {
val config = generateJSONObjectConfig("activate-flag", JSONObject(mapOf("test" to "value")))
val config = generateJSONObjectConfig("activate-flag", JSONObject(mapOf("test1" to "value1")))
val config2 = generateJSONObjectConfig("activate-flag", JSONObject(mapOf("test2" to "value2")))

mockWebServer.enqueue(MockResponse().setResponseCode(200).setBody(objectMapper.writeValueAsString(config)))
Expand All @@ -455,7 +470,7 @@ class DVCClientTests {
val countDownLatch = CountDownLatch(2)
val initializedLatch = CountDownLatch(1)

val variable = client.variable("activate-flag", JSONObject(mapOf("arg" to "yeah")))
val variable = client.variable("activate-flag", JSONObject(mapOf("test" to "default")))
variable.onUpdate {
countDownLatch.countDown()
}
Expand All @@ -470,9 +485,8 @@ class DVCClientTests {
}
})

Assertions.assertEquals(variable.value.getString("arg"), "yeah")
initializedLatch.await(2000, TimeUnit.MILLISECONDS)
Assertions.assertEquals(variable.value.getString("test"), "value")
Assertions.assertEquals(variable.value.getString("test1"), "value1")

countDownLatch.await(3000, TimeUnit.MILLISECONDS)
Assertions.assertEquals(variable.value.getString("test2"), "value2")
Expand Down Expand Up @@ -1061,6 +1075,7 @@ class DVCClientTests {
val jsonValue = client.variableValue("test-feature-json", defaultJSON)
val boolVar = client.variable("test-feature", false)
val boolValue = client.variableValue("test-feature", false)
println("--- BOOL VALUE: " + boolValue)
val numVar = client.variable("test-feature-number", 0)
val numValue = client.variableValue("test-feature-number", 0)
val strVar = client.variable("test-feature-string", "Not activated")
Expand Down

0 comments on commit 139805a

Please sign in to comment.