generated from pricelees/issue-pr-template
[#44] 매장 기능 도입 #45
@ -17,6 +17,7 @@ fun runTest(
|
|||||||
on: RequestSpecification.() -> Response,
|
on: RequestSpecification.() -> Response,
|
||||||
expect: ValidatableResponse.() -> Unit
|
expect: ValidatableResponse.() -> Unit
|
||||||
): ValidatableResponse {
|
): ValidatableResponse {
|
||||||
|
println("[runTest] 테스트 시작")
|
||||||
return Given {
|
return Given {
|
||||||
contentType(MediaType.APPLICATION_JSON_VALUE)
|
contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||||
token?.also { header("Authorization", "Bearer $token") }
|
token?.also { header("Authorization", "Bearer $token") }
|
||||||
|
|||||||
@ -22,20 +22,28 @@ class TestAuthUtil(
|
|||||||
private val storeRepository: StoreRepository,
|
private val storeRepository: StoreRepository,
|
||||||
) {
|
) {
|
||||||
fun createAdmin(admin: AdminEntity): AdminEntity {
|
fun createAdmin(admin: AdminEntity): AdminEntity {
|
||||||
|
println("[TestAuthUtil] 관리자 생성 시작. id=${admin.id}")
|
||||||
|
|
||||||
val storeId = admin.storeId
|
val storeId = admin.storeId
|
||||||
if (storeId != null && storeRepository.findByIdOrNull(storeId) == null) {
|
if (storeId != null && storeRepository.findByIdOrNull(storeId) == null) {
|
||||||
|
println("[TestAuthUtil] 매장 정보 없음. 매장 생성 시작. storeId=${storeId} adminId=${admin.id}")
|
||||||
storeRepository.save(
|
storeRepository.save(
|
||||||
StoreFixture.create(
|
StoreFixture.create(
|
||||||
id = storeId,
|
id = storeId,
|
||||||
businessRegNum = randomBusinessRegNum(),
|
businessRegNum = randomBusinessRegNum(),
|
||||||
)
|
)
|
||||||
)
|
).also {
|
||||||
|
println("[TestAuthUtil] 매장 생성 완료. storeId=${storeId} adminId=${admin.id}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return adminRepository.save(admin)
|
return adminRepository.save(admin).also {
|
||||||
|
println("[TestAuthUtil] 관리자 생성 완료. id=${admin.id}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun signup(request: UserCreateRequest): UserEntity {
|
fun signup(request: UserCreateRequest): UserEntity {
|
||||||
|
println("[TestAuthUtil] 회원가입 시작: $request")
|
||||||
val userId: Long = Given {
|
val userId: Long = Given {
|
||||||
contentType(MediaType.APPLICATION_JSON_VALUE)
|
contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||||
body(request)
|
body(request)
|
||||||
@ -48,14 +56,16 @@ class TestAuthUtil(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return userRepository.findByIdOrNull(userId)
|
return userRepository.findByIdOrNull(userId)
|
||||||
|
?.also { println("[TestAuthUtil] 회원가입 완료. 회원 반환: $userId") }
|
||||||
?: throw AssertionError("Unexpected Exception Occurred.")
|
?: throw AssertionError("Unexpected Exception Occurred.")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun adminLogin(admin: AdminEntity): String {
|
fun adminLogin(admin: AdminEntity): String {
|
||||||
|
println("[TestAuthUtil] 관리자 로그인 시작. id=${admin.id}, account=${admin.account}")
|
||||||
val saved = createAdmin(admin)
|
val saved = createAdmin(admin)
|
||||||
val requestBody = LoginRequest(saved.account, saved.password, PrincipalType.ADMIN)
|
val requestBody = LoginRequest(saved.account, saved.password, PrincipalType.ADMIN)
|
||||||
|
|
||||||
return Given {
|
val token: String = Given {
|
||||||
contentType(MediaType.APPLICATION_JSON_VALUE)
|
contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||||
body(requestBody)
|
body(requestBody)
|
||||||
} When {
|
} When {
|
||||||
@ -65,17 +75,21 @@ class TestAuthUtil(
|
|||||||
} Extract {
|
} Extract {
|
||||||
path("data.accessToken")
|
path("data.accessToken")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return token.also { println("[TestAuthUtil] 관리자 로그인 완료. id=${admin.id}, account=${admin.account}") }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun defaultStoreAdminLogin(): String = adminLogin(AdminFixture.storeDefault)
|
fun defaultStoreAdminLogin(): String = adminLogin(AdminFixture.storeDefault)
|
||||||
fun defaultHqAdminLogin(): String = adminLogin(AdminFixture.hqDefault)
|
fun defaultHqAdminLogin(): String = adminLogin(AdminFixture.hqDefault)
|
||||||
|
|
||||||
fun userLogin(user: UserEntity): String {
|
fun userLogin(user: UserEntity): String {
|
||||||
|
println("[TestAuthUtil] 회원 로그인 시작. id=${user.id}, email=${user.email}")
|
||||||
if (userRepository.findByEmail(user.email) == null) {
|
if (userRepository.findByEmail(user.email) == null) {
|
||||||
|
println("[TestAuthUtil] 회원 정보 없음. 회원 생성 시작. email=${user.email}")
|
||||||
userRepository.save(user)
|
userRepository.save(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Given {
|
val token: String = Given {
|
||||||
contentType(MediaType.APPLICATION_JSON_VALUE)
|
contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||||
body(LoginRequest(account = user.email, password = user.password, principalType = PrincipalType.USER))
|
body(LoginRequest(account = user.email, password = user.password, principalType = PrincipalType.USER))
|
||||||
} When {
|
} When {
|
||||||
@ -85,6 +99,8 @@ class TestAuthUtil(
|
|||||||
} Extract {
|
} Extract {
|
||||||
path("data.accessToken")
|
path("data.accessToken")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return token.also { println("[TestAuthUtil] 회원 로그인 완료. id=${user.id}, email=${user.email}") }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun defaultUserLogin(): String = userLogin(UserFixture.default)
|
fun defaultUserLogin(): String = userLogin(UserFixture.default)
|
||||||
|
|||||||
@ -3,7 +3,11 @@ package roomescape.supports
|
|||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
inline fun <T> initialize(name: String, block: () -> T): T {
|
inline fun <T> initialize(name: String, block: () -> T): T {
|
||||||
return block()
|
println("초기화 작업 시작: $name")
|
||||||
|
return block().also {
|
||||||
|
println("초기화 작업 완료: $name")
|
||||||
|
println("===================================")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun randomPhoneNumber(): String {
|
fun randomPhoneNumber(): String {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user