Skip to content

Commit 83bd2e7

Browse files
authored
chore: add more tests to Formbricks Api Service (#15)
* chore: add more tests to Formbricks API Service * add more tests
1 parent e41b52a commit 83bd2e7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

android/src/androidTest/java/com/formbricks/android/network/FormbricksApiServiceInstrumentedTest.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,31 @@ class FormbricksApiServiceInstrumentedTest {
5050
assertTrue(result.isFailure)
5151
}
5252

53+
@Test
54+
fun testPostUser_withNullAttributes_handlesErrorGracefully() {
55+
val dummyBody = PostUserBody("dummy-user-id", null)
56+
val result = apiService.postUser("dummy-environment-id", dummyBody)
57+
assertTrue(result.isFailure)
58+
}
59+
60+
@Test
61+
fun testInitialize_multipleTimes_noCrash() {
62+
try {
63+
apiService.initialize("https://example.com", isLoggingEnabled = false)
64+
apiService.initialize("https://another-url.com", isLoggingEnabled = true)
65+
} catch (e: Exception) {
66+
fail("Multiple initializations should not throw: ${e.message}")
67+
}
68+
}
69+
70+
@Test
71+
fun testGetEnvironmentStateObject_beforeInitialize_returnsFailure() {
72+
val uninitializedService = FormbricksApiService()
73+
val result = uninitializedService.getEnvironmentStateObject("dummy")
74+
assertTrue(result.isFailure)
75+
assertTrue(result.exceptionOrNull() is UninitializedPropertyAccessException)
76+
}
77+
5378
// Add more integration-style tests as needed, e.g.:
5479
// - testGetEnvironmentStateObject_withMockServer
5580
// - testPostUser_withMockServer

0 commit comments

Comments
 (0)