[#22] 프론트엔드 React 전환 및 인증 API 수정 #23

Merged
pricelees merged 9 commits from refactor/#22 into main 2025-07-27 03:39:20 +00:00
6 changed files with 272 additions and 259 deletions
Showing only changes of commit ede2e7f624 - Show all commits

View File

@ -31,7 +31,6 @@ class AuthInterceptor(
val member: MemberEntity = findMember(request, response)
if (admin != null && !member.isAdmin()) {
response.sendRedirect("/login")
throw AuthException(AuthErrorCode.ACCESS_DENIED)
}
@ -45,7 +44,6 @@ class AuthInterceptor(
return memberService.findById(memberId)
} catch (e: Exception) {
response.sendRedirect("/login")
throw e
}
}

View File

@ -61,7 +61,7 @@ class AuthControllerTest(
memberRepository.findByEmailAndPassword(userRequest.email, userRequest.password)
} returns null
Then("에러 응답") {
Then("에러 응답을 받는다.") {
val expectedError = AuthErrorCode.LOGIN_FAILED
runPostTest(
mockMvc = mockMvc,
@ -118,7 +118,7 @@ class AuthControllerTest(
every { jwtHandler.getMemberIdFromToken(any()) } returns invalidMemberId
every { memberRepository.findByIdOrNull(invalidMemberId) } returns null
Then("에러 응답.") {
Then("에러 응답을 받는다.") {
val expectedError = AuthErrorCode.UNIDENTIFIABLE_MEMBER
runGetTest(
mockMvc = mockMvc,
@ -137,15 +137,14 @@ class AuthControllerTest(
When("로그인 상태가 아니라면") {
doNotLogin()
Then("로그인 페이지로 이동한다.") {
Then("에러 응답을 받는다.") {
val expectedError = AuthErrorCode.INVALID_TOKEN
runPostTest(
mockMvc = mockMvc,
endpoint = endpoint,
) {
status { is3xxRedirection() }
header {
string("Location", "/login")
}
status { isEqualTo(expectedError.httpStatus.value()) }
jsonPath("$.code", equalTo(expectedError.errorCode))
}
}
}

View File

@ -7,6 +7,7 @@ import io.mockk.every
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.test.web.servlet.MockMvc
import roomescape.auth.exception.AuthErrorCode
import roomescape.member.web.MemberController
import roomescape.member.web.MemberRetrieveListResponse
import roomescape.util.MemberFixture
@ -51,32 +52,32 @@ class MemberControllerTest(
}
}
`when`("관리자가 아니면 로그인 페이지로 이동한다.") {
`when`("관리자가 아니면 에러 응답을 받는다.") {
then("비회원") {
doNotLogin()
val expectedError = AuthErrorCode.INVALID_TOKEN
runGetTest(
mockMvc = mockMvc,
endpoint = endpoint,
) {
status { is3xxRedirection() }
header {
string("Location", "/login")
}
status { isEqualTo(expectedError.httpStatus.value()) }
}.andExpect {
jsonPath("$.code") { value(expectedError.errorCode) }
}
}
then("일반 회원") {
loginAsUser()
val expectedError = AuthErrorCode.ACCESS_DENIED
runGetTest(
mockMvc = mockMvc,
endpoint = endpoint,
) {
status { is3xxRedirection() }
header {
string("Location", "/login")
}
status { isEqualTo(expectedError.httpStatus.value()) }
}.andExpect {
jsonPath("$.code") { value(expectedError.errorCode) }
}
}
}

View File

@ -9,14 +9,13 @@ import io.restassured.module.kotlin.extensions.Given
import io.restassured.module.kotlin.extensions.Then
import io.restassured.module.kotlin.extensions.When
import jakarta.persistence.EntityManager
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.equalTo
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.server.LocalServerPort
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.transaction.support.TransactionTemplate
import roomescape.auth.exception.AuthErrorCode
import roomescape.auth.infrastructure.jwt.JwtHandler
import roomescape.auth.web.support.MemberIdResolver
import roomescape.member.business.MemberService
@ -108,7 +107,7 @@ class ReservationControllerTest(
}
}
test("결제 완료 후 예약 / 결제 정보 저장 과정에서 에러 발생시 결제 취소 후 에러 응답") {
test("결제 완료 후 예약 / 결제 정보 저장 과정에서 에러 발생시 결제 취소 후 에러 응답을 받는다.") {
val reservationRequest = createRequest()
val paymentApproveResponse = PaymentFixture.createApproveResponse().copy(
paymentKey = reservationRequest.paymentKey,
@ -203,6 +202,7 @@ class ReservationControllerTest(
test("관리자만 검색할 수 있다.") {
login(reservations.keys.first())
val expectedError = AuthErrorCode.ACCESS_DENIED
Given {
port(port)
@ -210,7 +210,8 @@ class ReservationControllerTest(
}.When {
get("/reservations/search")
}.Then {
header(HttpHeaders.CONTENT_TYPE, containsString(MediaType.TEXT_HTML_VALUE))
statusCode(expectedError.httpStatus.value())
body("code", equalTo(expectedError.errorCode))
}
}
@ -309,14 +310,15 @@ class ReservationControllerTest(
test("관리자만 예약을 삭제할 수 있다.") {
login(MemberFixture.create(role = Role.MEMBER))
val reservation: ReservationEntity = reservations.values.flatten().first()
val expectedError = AuthErrorCode.ACCESS_DENIED
Given {
port(port)
}.When {
delete("/reservations/${reservation.id}")
}.Then {
statusCode(302)
header(HttpHeaders.LOCATION, containsString("/login"))
statusCode(expectedError.httpStatus.value())
body("code", equalTo(expectedError.errorCode))
}
}
@ -425,6 +427,7 @@ class ReservationControllerTest(
test("관리자가 아니면 조회할 수 없다.") {
login(MemberFixture.create(role = Role.MEMBER))
val expectedError = AuthErrorCode.ACCESS_DENIED
Given {
port(port)
@ -432,7 +435,8 @@ class ReservationControllerTest(
}.When {
get("/reservations/waiting")
}.Then {
header(HttpHeaders.CONTENT_TYPE, containsString(MediaType.TEXT_HTML_VALUE))
statusCode(expectedError.httpStatus.value())
body("code", equalTo(expectedError.errorCode))
}
}
@ -566,14 +570,14 @@ class ReservationControllerTest(
context("POST /reservations/waiting/{id}/confirm") {
test("관리자만 승인할 수 있다.") {
login(MemberFixture.create(role = Role.MEMBER))
val expectedError = AuthErrorCode.ACCESS_DENIED
Given {
port(port)
}.When {
post("/reservations/waiting/1/confirm")
}.Then {
statusCode(302)
header(HttpHeaders.LOCATION, containsString("/login"))
statusCode(expectedError.httpStatus.value())
body("code", equalTo(expectedError.errorCode))
}
}
@ -642,14 +646,15 @@ class ReservationControllerTest(
context("POST /reservations/waiting/{id}/reject") {
test("관리자만 거절할 수 있다.") {
login(MemberFixture.create(role = Role.MEMBER))
val expectedError = AuthErrorCode.ACCESS_DENIED
Given {
port(port)
}.When {
post("/reservations/waiting/1/reject")
}.Then {
statusCode(302)
header(HttpHeaders.LOCATION, containsString("/login"))
statusCode(expectedError.httpStatus.value())
body("code", equalTo(expectedError.errorCode))
}
}

View File

@ -8,6 +8,7 @@ import io.kotest.matchers.shouldBe
import io.mockk.every
import io.mockk.just
import io.mockk.runs
import org.hamcrest.Matchers.equalTo
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
@ -34,15 +35,15 @@ class ThemeControllerTest(mockMvc: MockMvc) : RoomescapeApiTest() {
When("로그인 상태가 아니라면") {
doNotLogin()
Then("로그인 페이지로 이동한다.") {
Then("에러 응답을 받는다.") {
val expectedError = AuthErrorCode.INVALID_TOKEN
runGetTest(
mockMvc = mockMvc,
endpoint = endpoint,
) {
status { is3xxRedirection() }
header {
string("Location", "/login")
}
status { isEqualTo(expectedError.httpStatus.value()) }
}.andExpect {
jsonPath("$.code") { value(expectedError.errorCode) }
}
}
}
@ -87,30 +88,30 @@ class ThemeControllerTest(mockMvc: MockMvc) : RoomescapeApiTest() {
When("로그인 상태가 아니라면") {
doNotLogin()
Then("로그인 페이지로 이동한다.") {
Then("에러 응답을 받는다.") {
val expectedError = AuthErrorCode.INVALID_TOKEN
runPostTest(
mockMvc = mockMvc,
endpoint = endpoint,
body = request,
) {
status { is3xxRedirection() }
header {
string("Location", "/login")
}
status { isEqualTo(expectedError.httpStatus.value()) }
jsonPath("$.code", equalTo(expectedError.errorCode))
}
}
}
When("관리자가 아닌 회원은") {
loginAsUser()
Then("로그인 페이지로 이동한다.") {
Then("에러 응답을 받는다.") {
val expectedError = AuthErrorCode.ACCESS_DENIED
runPostTest(
mockMvc = mockMvc,
endpoint = endpoint,
body = request,
) {
status { is3xxRedirection() }
jsonPath("$.code") { value(AuthErrorCode.ACCESS_DENIED.errorCode) }
status { isEqualTo(expectedError.httpStatus.value()) }
jsonPath("$.code") { value(expectedError.errorCode) }
}
}
}
@ -120,7 +121,7 @@ class ThemeControllerTest(mockMvc: MockMvc) : RoomescapeApiTest() {
val expectedError = ThemeErrorCode.THEME_NAME_DUPLICATED
Then("에러 응답.") {
Then("에러 응답을 받는다.") {
every {
themeRepository.existsByName(request.name)
} returns true
@ -232,28 +233,28 @@ class ThemeControllerTest(mockMvc: MockMvc) : RoomescapeApiTest() {
When("로그인 상태가 아니라면") {
doNotLogin()
Then("로그인 페이지로 이동한다.") {
Then("에러 응답을 받는다.") {
val expectedError = AuthErrorCode.INVALID_TOKEN
runDeleteTest(
mockMvc = mockMvc,
endpoint = endpoint,
) {
status { is3xxRedirection() }
header {
string("Location", "/login")
}
status { isEqualTo(expectedError.httpStatus.value()) }
jsonPath("$.code", equalTo(expectedError.errorCode))
}
}
}
When("관리자가 아닌 회원은") {
loginAsUser()
Then("로그인 페이지로 이동한다.") {
Then("에러 응답을 받는다.") {
val expectedError = AuthErrorCode.ACCESS_DENIED
runDeleteTest(
mockMvc = mockMvc,
endpoint = endpoint,
) {
status { is3xxRedirection() }
jsonPath("$.code") { value(AuthErrorCode.ACCESS_DENIED.errorCode) }
status { isEqualTo(expectedError.httpStatus.value()) }
jsonPath("$.code", equalTo(expectedError.errorCode))
}
}
}
@ -262,7 +263,7 @@ class ThemeControllerTest(mockMvc: MockMvc) : RoomescapeApiTest() {
loginAsAdmin()
val expectedError = ThemeErrorCode.THEME_ALREADY_RESERVED
Then("에러 응답") {
Then("에러 응답을 받는다.") {
every {
themeRepository.isReservedTheme(themeId)
} returns true

View File

@ -6,11 +6,13 @@ import io.kotest.assertions.assertSoftly
import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.shouldBe
import io.mockk.every
import org.hamcrest.Matchers.equalTo
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.context.annotation.Import
import org.springframework.data.repository.findByIdOrNull
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import roomescape.auth.exception.AuthErrorCode
import roomescape.common.config.JacksonConfig
import roomescape.reservation.infrastructure.persistence.ReservationRepository
import roomescape.time.business.TimeService
@ -72,14 +74,19 @@ class TimeControllerTest(
When("관리자가 아닌 경우") {
loginAsUser()
val expectedError = AuthErrorCode.ACCESS_DENIED
Then("로그인 페이지로 이동") {
Then("에러 응답을 받는다.") {
runGetTest(
mockMvc = mockMvc,
endpoint = endpoint,
) {
status { is3xxRedirection() }
header { string("Location", "/login") }
status { isEqualTo(expectedError.httpStatus.value()) }
}.andExpect {
content {
contentType(MediaType.APPLICATION_JSON)
jsonPath("$.code") { value(expectedError.errorCode) }
}
}
}
}
@ -152,14 +159,15 @@ class TimeControllerTest(
When("관리자가 아닌 경우") {
loginAsUser()
Then("로그인 페이지로 이동") {
Then("에러 응답을 받는다.") {
val expectedError = AuthErrorCode.ACCESS_DENIED
runPostTest(
mockMvc = mockMvc,
endpoint = endpoint,
body = TimeFixture.create(),
) {
status { is3xxRedirection() }
header { string("Location", "/login") }
status { isEqualTo(expectedError.httpStatus.value()) }
jsonPath("$.code", equalTo(expectedError.errorCode))
}
}
}
@ -232,13 +240,14 @@ class TimeControllerTest(
When("관리자가 아닌 경우") {
loginAsUser()
Then("로그인 페이지로 이동") {
Then("에러 응답을 받는다.") {
val expectedError = AuthErrorCode.ACCESS_DENIED
runDeleteTest(
mockMvc = mockMvc,
endpoint = endpoint,
) {
status { is3xxRedirection() }
header { string("Location", "/login") }
status { isEqualTo(expectedError.httpStatus.value()) }
jsonPath("$.code", equalTo(expectedError.errorCode))
}
}
}