[#34] 회원 / 인증 도메인 재정의 #43

Merged
pricelees merged 73 commits from refactor/#34 into main 2025-09-13 10:13:45 +00:00
Showing only changes of commit 1ddf812d1c - Show all commits

View File

@ -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 여부를 확인할 프로퍼티 이름
*/ */