-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: PUT /users/me #109
Conversation
private fun validateNicknameDuplicated(nickname: String) { | ||
if (userRepository.existsUserByNickname(nickname)) { | ||
throw PlatformException("invalid nickname: duplicated") | ||
} | ||
} | ||
|
||
private fun validateNicknameLength(nickname: String) { | ||
if (nickname.toByteArray().size < 4) { | ||
throw PlatformException("invalid nickname: too short") | ||
} | ||
if (nickname.toByteArray().size > 16) { | ||
throw PlatformException("invalid nickname: too long") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q:為什麼需要先轉換成 ByteArray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因為之前的結論是限制字元長度,所以這邊先轉成字元再判斷長度:
最少 4 英文字元 (= 2 中文字)
最長 16 英文字元 (= 8 中文字)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那可以把 nickname.toByteArray()
宣告成變數 🐣
cb64692
to
4f2ad30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review done.
application/src/main/kotlin/tw/waterballsa/gaas/application/usecases/UpdateUserUseCase.kt
Outdated
Show resolved
Hide resolved
application/src/main/kotlin/tw/waterballsa/gaas/application/usecases/UpdateUserUseCase.kt
Outdated
Show resolved
Hide resolved
spring/src/main/kotlin/tw/waterballsa/gaas/spring/controllers/UserController.kt
Outdated
Show resolved
Hide resolved
spring/src/main/kotlin/tw/waterballsa/gaas/spring/controllers/UserController.kt
Outdated
Show resolved
Hide resolved
spring/src/main/kotlin/tw/waterballsa/gaas/spring/controllers/presenter/UpdateUserPresenter.kt
Outdated
Show resolved
Hide resolved
spring/src/main/kotlin/tw/waterballsa/gaas/spring/repositories/SpringUserRepository.kt
Outdated
Show resolved
Hide resolved
spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/AbstractSpringBootTest.kt
Outdated
Show resolved
Hide resolved
private val nicknameByteSizeMinimum: Int = 4 | ||
private val nicknameByteSizeMaximum: Int = 16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
companion object {
private const val NICK_NAME_MINIMUM_BYTE_SIZE = 4
private const val NICK_NAME_MAXIMUM_BYTE_SIZE = 16
}
private val nicknameByteSizeMaximum: Int = 16 | ||
|
||
fun updateNickname(nickname: String) { | ||
if (nickname.toByteArray().size < nicknameByteSizeMinimum) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nickname.toByteArray()
用變數接
var Jwt.email: String? | ||
get() = claims["email"] as String? | ||
set(value) { | ||
claims["email"] = value | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private val Jwt.email: String
get() = claims["email"]?.let { it as String }
?: throw PlatformException("JWT email should exist.")
fun givenUserNickname_whenUpdateEnglishNickname_thenShouldUpdateNickname() { | ||
givenUserNickname() | ||
.whenUpdateUserSelf(UpdateUserRequest("my nick name")) | ||
.thenShouldUpdateNickname("my nick name") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 這個測試案例可以改成這樣:
fun givenUserNamedNeverever_whenChangeUserNicknameToAbc_thenUserNickNameShouldBeAbc() {
givenUserNickname("Neverever")
.whenChangeUserNickName(UpdateUserRequest("abc"))
.thenShouldUpdateNickname("abc")
}
- 下面的測試案例名稱可以依照上方範例檢視然後修改
private val nicknameByteSizeMinimum: Int = 4 | ||
private val nicknameByteSizeMaximum: Int = 16 | ||
|
||
fun updateNickname(nickname: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fun changeNickname(nickname: String)
private fun givenUserNickname(): User { | ||
val user = User(User.Id("1"), "[email protected]", "Neverever", mockUser.identities) | ||
return userRepository.createUser(user) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在存進資料庫前不會有任何 UserId 存在
} | ||
|
||
private fun givenAnotherUserNickname(): User { | ||
val user = User(User.Id("2"), "[email protected]", "周杰倫", mockUser.identities) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto,在存進資料庫前不會有任何 UserId 存在
.getBody(PlatformViewModel::class.java) | ||
.also { assertThat(it.message).contains(message) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 應該可以用
jsonPath
比對 - 將
exists()
改為value()
就可以比對了
.also { assertThat(it!!.nickname).isEqualTo(nickname) } | ||
} | ||
|
||
private fun ResultActions.thenShouldUpdateNicknameFailed(message: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thenShouldChangeNicknameFailed
@@ -59,4 +119,20 @@ class UserControllerTest @Autowired constructor( | |||
.andExpect(jsonPath("$.nickname").doesNotExist()) | |||
} | |||
|
|||
private fun ResultActions.thenShouldUpdateNickname(nickname: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thenUserNickNameSholdBeChanged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review done.
spring/src/main/kotlin/tw/waterballsa/gaas/spring/controllers/OAuth2Controller.kt
Outdated
Show resolved
Hide resolved
spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/UserControllerTest.kt
Outdated
Show resolved
Hide resolved
spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/UserControllerTest.kt
Outdated
Show resolved
Hide resolved
spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/UserControllerTest.kt
Outdated
Show resolved
Hide resolved
spring/src/test/kotlin/tw/waterballsa/gaas/spring/it/controllers/UserControllerTest.kt
Outdated
Show resolved
Hide resolved
6fdde08
to
675f80c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Why need this change? / Root cause:
Changes made:
Test Scope / Change impact:
Issue