generated from pricelees/issue-pr-template
feat: RestAssuredUtils에 예외 처리 전용 테스트 추가
This commit is contained in:
parent
8d86dd8a70
commit
1ddf812d1c
@ -7,7 +7,9 @@ import io.restassured.module.kotlin.extensions.When
|
|||||||
import io.restassured.response.Response
|
import io.restassured.response.Response
|
||||||
import io.restassured.response.ValidatableResponse
|
import io.restassured.response.ValidatableResponse
|
||||||
import io.restassured.specification.RequestSpecification
|
import io.restassured.specification.RequestSpecification
|
||||||
|
import org.hamcrest.CoreMatchers.equalTo
|
||||||
import org.springframework.data.repository.findByIdOrNull
|
import org.springframework.data.repository.findByIdOrNull
|
||||||
|
import org.springframework.http.HttpMethod
|
||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import roomescape.admin.infrastructure.persistence.AdminEntity
|
import roomescape.admin.infrastructure.persistence.AdminEntity
|
||||||
@ -16,9 +18,9 @@ import roomescape.auth.web.LoginRequest
|
|||||||
import roomescape.auth.web.LoginRequestV2
|
import roomescape.auth.web.LoginRequestV2
|
||||||
import roomescape.common.config.next
|
import roomescape.common.config.next
|
||||||
import roomescape.common.dto.PrincipalType
|
import roomescape.common.dto.PrincipalType
|
||||||
|
import roomescape.common.exception.ErrorCode
|
||||||
import roomescape.member.infrastructure.persistence.*
|
import roomescape.member.infrastructure.persistence.*
|
||||||
import roomescape.member.web.UserCreateRequest
|
import roomescape.member.web.UserCreateRequest
|
||||||
import roomescape.member.web.toEntity
|
|
||||||
|
|
||||||
class AuthUtil(
|
class AuthUtil(
|
||||||
private val memberRepository: MemberRepository,
|
private val memberRepository: MemberRepository,
|
||||||
@ -87,10 +89,11 @@ class AuthUtil(
|
|||||||
if (adminRepository.findByAccount(admin.account) == null) {
|
if (adminRepository.findByAccount(admin.account) == null) {
|
||||||
adminRepository.save(admin)
|
adminRepository.save(admin)
|
||||||
}
|
}
|
||||||
|
val requestBody = LoginRequestV2(admin.account, admin.password, PrincipalType.ADMIN)
|
||||||
|
|
||||||
return Given {
|
return Given {
|
||||||
contentType(MediaType.APPLICATION_JSON_VALUE)
|
contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||||
body(LoginRequestV2(account = admin.account, password = admin.password, principalType = PrincipalType.ADMIN))
|
body(requestBody)
|
||||||
} When {
|
} When {
|
||||||
post("/auth/login")
|
post("/auth/login")
|
||||||
} Then {
|
} 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 여부를 확인할 프로퍼티 이름
|
* @param props: RestAssured 응답 Body 에서 존재 & Null 여부를 확인할 프로퍼티 이름
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user