diff --git a/domain/src/main/kotlin/tw/waterballsa/gaas/domain/User.kt b/domain/src/main/kotlin/tw/waterballsa/gaas/domain/User.kt index 7af6c449..54da89fb 100644 --- a/domain/src/main/kotlin/tw/waterballsa/gaas/domain/User.kt +++ b/domain/src/main/kotlin/tw/waterballsa/gaas/domain/User.kt @@ -16,6 +16,9 @@ class User( private const val NICKNAME_MAXIMUM_BYTE_SIZE = 16 } + constructor(email: String, nickname: String, identities: MutableList ) : + this(null, email, nickname, identities) + fun changeNickname(nickname: String) { val nicknameByteSize = nickname.toByteArray().size diff --git a/spring/src/main/kotlin/tw/waterballsa/gaas/spring/controllers/OAuth2Controller.kt b/spring/src/main/kotlin/tw/waterballsa/gaas/spring/controllers/OAuth2Controller.kt index e0bdc802..5944a298 100644 --- a/spring/src/main/kotlin/tw/waterballsa/gaas/spring/controllers/OAuth2Controller.kt +++ b/spring/src/main/kotlin/tw/waterballsa/gaas/spring/controllers/OAuth2Controller.kt @@ -45,7 +45,7 @@ class OAuth2Controller( } val Jwt.email: String - get() = claims["email"]?.let { it as String } + get() = claims["email"]?.toString() ?: throw PlatformException("JWT email should exist.") val Jwt.identityProviderId: String diff --git a/spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/UserControllerTest.kt b/spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/UserControllerTest.kt index 54bba0ff..200abbd0 100644 --- a/spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/UserControllerTest.kt +++ b/spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/UserControllerTest.kt @@ -82,12 +82,12 @@ class UserControllerTest @Autowired constructor( } private fun givenUserNickname(nickname: String): User { - val user = User(null, "userA@example.com", nickname, mockUser.identities) + val user = User("userA@example.com", nickname, mockUser.identities) return userRepository.createUser(user) } private fun givenAnotherUserNickname(nickname: String): User { - val user = User(null, "userB@example.com", nickname, mockUser.identities) + val user = User("userB@example.com", nickname, mockUser.identities) return userRepository.createUser(user) } @@ -103,7 +103,6 @@ class UserControllerTest @Autowired constructor( .withJwt(toJwt()) ) - private fun ResultActions.thenGetUserSuccessfully() { this.andExpect(status().isOk) .andExpect(jsonPath("$.id").value(mockUser.id!!.value)) @@ -119,10 +118,10 @@ class UserControllerTest @Autowired constructor( } private fun ResultActions.thenUserNicknameShouldBeChanged(nickname: String) { - val userViewModel = andExpect(status().isOk) + val user = andExpect(status().isOk) .getBody(UpdateUserViewModel::class.java) - userRepository.findById(userViewModel.id) + userRepository.findById(user.id) .also { assertThat(it).isNotNull } .also { assertThat(it!!.nickname).isEqualTo(nickname) } }