generated from pricelees/issue-pr-template
[#34] 회원 / 인증 도메인 재정의 #43
@ -7,7 +7,9 @@ import io.restassured.module.kotlin.extensions.When
|
||||
import io.restassured.response.Response
|
||||
import io.restassured.response.ValidatableResponse
|
||||
import io.restassured.specification.RequestSpecification
|
||||
import org.hamcrest.CoreMatchers.equalTo
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.http.HttpMethod
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import roomescape.admin.infrastructure.persistence.AdminEntity
|
||||
@ -16,9 +18,9 @@ import roomescape.auth.web.LoginRequest
|
||||
import roomescape.auth.web.LoginRequestV2
|
||||
import roomescape.common.config.next
|
||||
import roomescape.common.dto.PrincipalType
|
||||
import roomescape.common.exception.ErrorCode
|
||||
import roomescape.member.infrastructure.persistence.*
|
||||
import roomescape.member.web.UserCreateRequest
|
||||
import roomescape.member.web.toEntity
|
||||
|
||||
class AuthUtil(
|
||||
private val memberRepository: MemberRepository,
|
||||
@ -87,10 +89,11 @@ class AuthUtil(
|
||||
if (adminRepository.findByAccount(admin.account) == null) {
|
||||
adminRepository.save(admin)
|
||||
}
|
||||
val requestBody = LoginRequestV2(admin.account, admin.password, PrincipalType.ADMIN)
|
||||
|
||||
return Given {
|
||||
contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||
body(LoginRequestV2(account = admin.account, password = admin.password, principalType = PrincipalType.ADMIN))
|
||||
body(requestBody)
|
||||
} When {
|
||||
post("/auth/login")
|
||||
} Then {
|
||||
@ -139,6 +142,37 @@ fun runTest(
|
||||
}
|
||||
}
|
||||
|
||||
fun runExceptionTest(
|
||||
token: String? = null,
|
||||
method: HttpMethod,
|
||||
requestBody: Any? = null,
|
||||
endpoint: String,
|
||||
expectedErrorCode: ErrorCode
|
||||
): ValidatableResponse {
|
||||
return runTest(
|
||||
token = token,
|
||||
using = {
|
||||
requestBody?.let { body(requestBody) } ?: this
|
||||
},
|
||||
on = {
|
||||
when (method) {
|
||||
HttpMethod.GET -> get(endpoint)
|
||||
HttpMethod.POST -> post(endpoint)
|
||||
HttpMethod.PATCH -> patch(endpoint)
|
||||
HttpMethod.DELETE -> delete(endpoint)
|
||||
|
||||
else -> {
|
||||
throw AssertionError("Unsupported HTTP method: $method")
|
||||
}
|
||||
}
|
||||
},
|
||||
expect = {
|
||||
statusCode(expectedErrorCode.httpStatus.value())
|
||||
body("code", equalTo(expectedErrorCode.errorCode))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param props: RestAssured 응답 Body 에서 존재 & Null 여부를 확인할 프로퍼티 이름
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user