From 955ee0f12659e8ede84ae61f24539ccae0fb20e2 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Sat, 20 Apr 2024 22:04:49 -0600 Subject: [PATCH] Fix failure in UserRouteTest --- .../test/kotlin/com/wbrawner/twigs/server/api/ApiTest.kt | 6 +++++- .../kotlin/com/wbrawner/twigs/server/api/UserRouteTest.kt | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/test/kotlin/com/wbrawner/twigs/server/api/ApiTest.kt b/app/src/test/kotlin/com/wbrawner/twigs/server/api/ApiTest.kt index fca73fd..fbbec1d 100644 --- a/app/src/test/kotlin/com/wbrawner/twigs/server/api/ApiTest.kt +++ b/app/src/test/kotlin/com/wbrawner/twigs/server/api/ApiTest.kt @@ -12,6 +12,7 @@ import io.ktor.client.* import io.ktor.client.plugins.contentnegotiation.* import io.ktor.serialization.kotlinx.json.* import io.ktor.server.testing.* +import kotlinx.serialization.json.Json import org.junit.jupiter.api.BeforeEach open class ApiTest { @@ -70,7 +71,10 @@ open class ApiTest { } val client = createClient { install(ContentNegotiation) { - json() + json(json = Json { + encodeDefaults = true + explicitNulls = false + }) } } test(client) diff --git a/app/src/test/kotlin/com/wbrawner/twigs/server/api/UserRouteTest.kt b/app/src/test/kotlin/com/wbrawner/twigs/server/api/UserRouteTest.kt index b49c173..61f2956 100644 --- a/app/src/test/kotlin/com/wbrawner/twigs/server/api/UserRouteTest.kt +++ b/app/src/test/kotlin/com/wbrawner/twigs/server/api/UserRouteTest.kt @@ -77,7 +77,7 @@ class UserRouteTest : ApiTest() { @Test fun `login with valid email and password returns 200`() = apiTest { client -> - val request = LoginRequest(TEST_USER.email, TEST_USER.password) + val request = LoginRequest(requireNotNull(TEST_USER.email), TEST_USER.password) val response = client.post("/api/users/login") { header("Content-Type", "application/json") setBody(request) @@ -172,14 +172,14 @@ class UserRouteTest : ApiTest() { val userResponse = response.body() assert(userResponse.id.isNotBlank()) assertEquals(request.username, userResponse.username) - assertEquals("", userResponse.email) + assertEquals(null, userResponse.email) assertEquals(initialUserCount + 1, userRepository.entities.size) val savedUser: User? = userRepository.findAll("newuser").firstOrNull() assertNotNull(savedUser) requireNotNull(savedUser) assertEquals(userResponse.id, savedUser.id) assertEquals(request.username, savedUser.name) - assertEquals("", savedUser.email) + assertEquals(null, savedUser.email) assertEquals("newpass", savedUser.password) }