diff --git a/src/test/kotlin/roomescape/theme/AdminThemeApiTest.kt b/src/test/kotlin/roomescape/theme/AdminThemeApiTest.kt index 898a3d46..61f76d12 100644 --- a/src/test/kotlin/roomescape/theme/AdminThemeApiTest.kt +++ b/src/test/kotlin/roomescape/theme/AdminThemeApiTest.kt @@ -1,9 +1,7 @@ package roomescape.theme -import io.kotest.matchers.date.shouldBeAfter import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe -import io.kotest.matchers.shouldNotBe import org.hamcrest.CoreMatchers.equalTo import org.springframework.data.repository.findByIdOrNull import org.springframework.http.HttpMethod @@ -54,7 +52,7 @@ class AdminThemeApiTest( val admin = AdminFixture.createStoreAdmin(permissionLevel = it) runExceptionTest( - token = testAuthUtil.adminLogin(admin), + token = testAuthUtil.adminLogin(admin).second, method = HttpMethod.POST, requestBody = createRequest, endpoint = endpoint, @@ -67,7 +65,7 @@ class AdminThemeApiTest( val admin = AdminFixture.createHqAdmin(permissionLevel = it) runExceptionTest( - token = testAuthUtil.adminLogin(admin), + token = testAuthUtil.adminLogin(admin).second, method = HttpMethod.POST, requestBody = createRequest, endpoint = endpoint, @@ -81,7 +79,7 @@ class AdminThemeApiTest( test("정상 생성 및 감사 정보 확인") { runTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, using = { body(createRequest) }, @@ -105,14 +103,12 @@ class AdminThemeApiTest( } test("이미 동일한 이름의 테마가 있으면 실패한다.") { - val token = testAuthUtil.defaultHqAdminLogin() - val alreadyExistsName: String = initialize("테스트를 위한 테마 생성 및 이름 반환") { - dummyInitializer.createTheme(token, createRequest).name + dummyInitializer.createTheme().name } runTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, using = { body(createRequest.copy(name = alreadyExistsName)) }, @@ -127,9 +123,8 @@ class AdminThemeApiTest( } test("금액이 ${MIN_PRICE}원 미만이면 실패한다.") { - val token = testAuthUtil.defaultHqAdminLogin() runTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, using = { body(createRequest.copy(price = (MIN_PRICE - 1))) }, @@ -146,7 +141,7 @@ class AdminThemeApiTest( context("입력된 시간이 ${MIN_DURATION}분 미만이면 실패한다.") { test("field: availableMinutes") { runExceptionTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.POST, endpoint = endpoint, requestBody = createRequest.copy(availableMinutes = (MIN_DURATION - 1).toShort()), @@ -156,7 +151,7 @@ class AdminThemeApiTest( test("field: expectedMinutesFrom") { runExceptionTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.POST, endpoint = endpoint, requestBody = createRequest.copy(expectedMinutesFrom = (MIN_DURATION - 1).toShort()), @@ -166,7 +161,7 @@ class AdminThemeApiTest( test("field: expectedMinutesTo") { runExceptionTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.POST, endpoint = endpoint, requestBody = createRequest.copy(expectedMinutesTo = (MIN_DURATION - 1).toShort()), @@ -178,7 +173,7 @@ class AdminThemeApiTest( context("시간 범위가 잘못 지정되면 실패한다.") { test("최소 예상 시간 > 최대 예상 시간") { runExceptionTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.POST, endpoint = endpoint, requestBody = createRequest.copy(expectedMinutesFrom = 100, expectedMinutesTo = 99), @@ -188,7 +183,7 @@ class AdminThemeApiTest( test("최대 예상 시간 > 이용 가능 시간") { runExceptionTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.POST, endpoint = endpoint, requestBody = createRequest.copy( @@ -204,7 +199,7 @@ class AdminThemeApiTest( context("입력된 인원이 ${MIN_PARTICIPANTS}명 미만이면 실패한다.") { test("field: minParticipants") { runExceptionTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.POST, endpoint = endpoint, requestBody = createRequest.copy(minParticipants = (MIN_PARTICIPANTS - 1).toShort()), @@ -214,7 +209,7 @@ class AdminThemeApiTest( test("field: maxParticipants") { runExceptionTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.POST, endpoint = endpoint, requestBody = createRequest.copy(maxParticipants = (MIN_PARTICIPANTS - 1).toShort()), @@ -226,7 +221,7 @@ class AdminThemeApiTest( context("인원 범위가 잘못 지정되면 실패한다.") { test("최소 인원 > 최대 인원") { runExceptionTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.POST, endpoint = endpoint, requestBody = createRequest.copy(minParticipants = 10, maxParticipants = 9), @@ -262,17 +257,15 @@ class AdminThemeApiTest( test("정상 응답") { val createdThemes = initialize("Active 상태 테마 2개 / Inactive 상태 테마 1개 생성") { - val token = testAuthUtil.defaultHqAdminLogin() - listOf( - dummyInitializer.createTheme(token, createRequest.copy(name = "test1", isActive = true)), - dummyInitializer.createTheme(token, createRequest.copy(name = "test2", isActive = false)), - dummyInitializer.createTheme(token, createRequest.copy(name = "test3", isActive = true)) + dummyInitializer.createTheme(createRequest.copy(name = "test1", isActive = true)), + dummyInitializer.createTheme(createRequest.copy(name = "test2", isActive = false)), + dummyInitializer.createTheme(createRequest.copy(name = "test3", isActive = true)) ) } runTest( - token = testAuthUtil.defaultStoreAdminLogin(), + token = testAuthUtil.defaultStoreAdminLogin().second, on = { get(endpoint) }, @@ -314,7 +307,7 @@ class AdminThemeApiTest( val admin = AdminFixture.createStoreAdmin(permissionLevel = it) runExceptionTest( - token = testAuthUtil.adminLogin(admin), + token = testAuthUtil.adminLogin(admin).second, method = HttpMethod.POST, requestBody = createRequest, endpoint = endpoint, @@ -326,13 +319,13 @@ class AdminThemeApiTest( test("정상 응답") { - val token = testAuthUtil.defaultHqAdminLogin() + val token = testAuthUtil.defaultHqAdminLogin().second val themes: List = initialize("Active 상태인 테마 1개 / Inactive 상태인 테마 2개 생성") { listOf( - dummyInitializer.createTheme(token, createRequest.copy(name = "active-1", isActive = true)), - dummyInitializer.createTheme(token, createRequest.copy(name = "inactive-1", isActive = false)), - dummyInitializer.createTheme(token, createRequest.copy(name = "inactive-2", isActive = false)) + dummyInitializer.createTheme(createRequest.copy(isActive = true)), + dummyInitializer.createTheme(createRequest.copy(isActive = false)), + dummyInitializer.createTheme(createRequest.copy(isActive = false)) ) } @@ -378,7 +371,7 @@ class AdminThemeApiTest( val admin = AdminFixture.createStoreAdmin(permissionLevel = it) runExceptionTest( - token = testAuthUtil.adminLogin(admin), + token = testAuthUtil.adminLogin(admin).second, method = HttpMethod.GET, endpoint = endpoint, expectedErrorCode = AuthErrorCode.ACCESS_DENIED @@ -390,7 +383,7 @@ class AdminThemeApiTest( val admin = AdminFixture.createHqAdmin(permissionLevel = it) runExceptionTest( - token = testAuthUtil.adminLogin(admin), + token = testAuthUtil.adminLogin(admin).second, method = HttpMethod.GET, endpoint = endpoint, expectedErrorCode = AuthErrorCode.ACCESS_DENIED @@ -401,13 +394,13 @@ class AdminThemeApiTest( } test("정상 응답") { - val token = testAuthUtil.defaultHqAdminLogin() + val token = testAuthUtil.defaultHqAdminLogin().second val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } runTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, on = { get("/admin/themes/${createdTheme.id}") }, @@ -433,7 +426,7 @@ class AdminThemeApiTest( test("테마가 없으면 실패한다.") { runExceptionTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.GET, endpoint = "/admin/themes/$INVALID_PK", expectedErrorCode = ThemeErrorCode.THEME_NOT_FOUND @@ -467,7 +460,7 @@ class AdminThemeApiTest( val admin = AdminFixture.createStoreAdmin(permissionLevel = it) runExceptionTest( - token = testAuthUtil.adminLogin(admin), + token = testAuthUtil.adminLogin(admin).second, method = HttpMethod.DELETE, endpoint = endpoint, expectedErrorCode = AuthErrorCode.ACCESS_DENIED @@ -479,7 +472,7 @@ class AdminThemeApiTest( val admin = AdminFixture.createHqAdmin(permissionLevel = it) runExceptionTest( - token = testAuthUtil.adminLogin(admin), + token = testAuthUtil.adminLogin(admin).second, method = HttpMethod.DELETE, endpoint = endpoint, expectedErrorCode = AuthErrorCode.ACCESS_DENIED @@ -490,13 +483,13 @@ class AdminThemeApiTest( } test("정상 삭제") { - val token = testAuthUtil.defaultHqAdminLogin() + val token = testAuthUtil.defaultHqAdminLogin().second val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } runTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, on = { delete("/admin/themes/${createdTheme.id}") }, @@ -510,7 +503,7 @@ class AdminThemeApiTest( test("테마가 없으면 실패한다.") { runExceptionTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.DELETE, endpoint = "/admin/themes/$INVALID_PK", expectedErrorCode = ThemeErrorCode.THEME_NOT_FOUND @@ -547,7 +540,7 @@ class AdminThemeApiTest( val admin = AdminFixture.createStoreAdmin(permissionLevel = it) runExceptionTest( - token = testAuthUtil.adminLogin(admin), + token = testAuthUtil.adminLogin(admin).second, method = HttpMethod.PATCH, endpoint = endpoint, requestBody = request, @@ -560,7 +553,7 @@ class AdminThemeApiTest( val admin = AdminFixture.createHqAdmin(permissionLevel = it) runExceptionTest( - token = testAuthUtil.adminLogin(admin), + token = testAuthUtil.adminLogin(admin).second, method = HttpMethod.PATCH, endpoint = endpoint, requestBody = request, @@ -574,11 +567,22 @@ class AdminThemeApiTest( val updateRequest = ThemeUpdateRequest(name = "modified") test("정상 수정 및 감사 정보 변경 확인") { - val createdTheme = initialize("테스트를 위한 관리자1의 테마 생성") { - dummyInitializer.createTheme(testAuthUtil.defaultHqAdminLogin(), createRequest) + val createdThemeId: Long = initialize("테스트를 위한 관리자1의 테마 생성") { + runTest( + token = testAuthUtil.defaultHqAdminLogin().second, + using = { + body(createRequest) + }, + on = { + post("/admin/themes") + }, + expect = { + statusCode(HttpStatus.CREATED.value()) + } + ).extract().path("data.id") } - val otherAdminToken: String = initialize("감사 정보 변경 확인을 위한 관리자2 로그인") { + val (otherAdmin, otherAdminToken) = initialize("감사 정보 변경 확인을 위한 관리자2 로그인") { testAuthUtil.adminLogin( AdminFixture.createHqAdmin(permissionLevel = AdminPermissionLevel.WRITABLE) ) @@ -590,30 +594,26 @@ class AdminThemeApiTest( body(updateRequest) }, on = { - patch("/admin/themes/${createdTheme.id}") + patch("/admin/themes/${createdThemeId}") }, expect = { statusCode(HttpStatus.OK.value()) } ).also { - val updatedTheme = themeRepository.findByIdOrNull(createdTheme.id)!! + val updatedTheme = themeRepository.findByIdOrNull(createdThemeId)!! - updatedTheme.id shouldBe createdTheme.id updatedTheme.name shouldBe updateRequest.name - updatedTheme.updatedBy shouldNotBe createdTheme.updatedBy - updatedTheme.updatedAt shouldBeAfter createdTheme.updatedAt + updatedTheme.updatedBy shouldBe otherAdmin.id } } test("입력값이 없으면 수정하지 않는다.") { - val token = testAuthUtil.defaultHqAdminLogin() - val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } runTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, using = { body(ThemeUpdateRequest()) }, @@ -633,7 +633,7 @@ class AdminThemeApiTest( test("테마가 없으면 실패한다.") { runExceptionTest( - token = testAuthUtil.defaultHqAdminLogin(), + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.PATCH, endpoint = "/admin/themes/$INVALID_PK", requestBody = updateRequest, @@ -642,13 +642,12 @@ class AdminThemeApiTest( } test("금액이 ${MIN_PRICE}원 미만이면 실패한다.") { - val token = testAuthUtil.defaultHqAdminLogin() val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } runExceptionTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.PATCH, endpoint = "/admin/themes/${createdTheme.id}", requestBody = updateRequest.copy(price = (MIN_PRICE - 1)), @@ -658,13 +657,12 @@ class AdminThemeApiTest( context("입력된 시간이 ${MIN_DURATION}분 미만이면 실패한다.") { test("field: availableMinutes") { - val token = testAuthUtil.defaultHqAdminLogin() val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } runExceptionTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.PATCH, endpoint = "/admin/themes/${createdTheme.id}", requestBody = updateRequest.copy(availableMinutes = (MIN_DURATION - 1).toShort()), @@ -673,13 +671,12 @@ class AdminThemeApiTest( } test("field: expectedMinutesFrom") { - val token = testAuthUtil.defaultHqAdminLogin() val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } runExceptionTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.PATCH, endpoint = "/admin/themes/${createdTheme.id}", requestBody = updateRequest.copy(expectedMinutesFrom = (MIN_DURATION - 1).toShort()), @@ -688,13 +685,12 @@ class AdminThemeApiTest( } test("field: expectedMinutesTo") { - val token = testAuthUtil.defaultHqAdminLogin() val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } runExceptionTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.PATCH, endpoint = "/admin/themes/${createdTheme.id}", requestBody = updateRequest.copy(expectedMinutesTo = (MIN_DURATION - 1).toShort()), @@ -705,13 +701,12 @@ class AdminThemeApiTest( context("시간 범위가 잘못 지정되면 실패한다.") { test("최소 예상 시간 > 최대 예상 시간") { - val token = testAuthUtil.defaultHqAdminLogin() val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } runExceptionTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.PATCH, endpoint = "/admin/themes/${createdTheme.id}", requestBody = updateRequest.copy(expectedMinutesFrom = 100, expectedMinutesTo = 99), @@ -721,9 +716,8 @@ class AdminThemeApiTest( test("최대 예상 시간 > 이용 가능 시간") { - val token = testAuthUtil.defaultHqAdminLogin() val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } val requestBody = updateRequest.copy( @@ -733,7 +727,7 @@ class AdminThemeApiTest( ) runExceptionTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.PATCH, endpoint = "/admin/themes/${createdTheme.id}", requestBody = requestBody, @@ -745,13 +739,12 @@ class AdminThemeApiTest( context("입력된 인원이 ${MIN_PARTICIPANTS}명 미만이면 실패한다.") { test("field: minParticipants") { - val token = testAuthUtil.defaultHqAdminLogin() val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } runExceptionTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.PATCH, endpoint = "/admin/themes/${createdTheme.id}", requestBody = updateRequest.copy(minParticipants = (MIN_PARTICIPANTS - 1).toShort()), @@ -760,13 +753,12 @@ class AdminThemeApiTest( } test("field: maxParticipants") { - val token = testAuthUtil.defaultHqAdminLogin() val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } runExceptionTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.PATCH, endpoint = "/admin/themes/${createdTheme.id}", requestBody = updateRequest.copy(maxParticipants = (MIN_PARTICIPANTS - 1).toShort()), @@ -777,13 +769,12 @@ class AdminThemeApiTest( context("인원 범위가 잘못 지정되면 실패한다.") { test("최소 인원 > 최대 인원") { - val token = testAuthUtil.defaultHqAdminLogin() val createdTheme = initialize("테스트를 위한 테마 생성") { - dummyInitializer.createTheme(token, createRequest) + dummyInitializer.createTheme() } runExceptionTest( - token = token, + token = testAuthUtil.defaultHqAdminLogin().second, method = HttpMethod.PATCH, endpoint = "/admin/themes/${createdTheme.id}", requestBody = updateRequest.copy(minParticipants = 10, maxParticipants = 9), diff --git a/src/test/kotlin/roomescape/theme/ThemeApiTest.kt b/src/test/kotlin/roomescape/theme/ThemeApiTest.kt index 596af41d..1ca12a4b 100644 --- a/src/test/kotlin/roomescape/theme/ThemeApiTest.kt +++ b/src/test/kotlin/roomescape/theme/ThemeApiTest.kt @@ -4,7 +4,6 @@ import org.hamcrest.CoreMatchers.equalTo import org.springframework.http.HttpMethod import org.springframework.http.HttpStatus import roomescape.supports.* -import roomescape.supports.ThemeFixture.createRequest import roomescape.theme.exception.ThemeErrorCode import roomescape.theme.infrastructure.persistence.ThemeEntity import roomescape.theme.web.ThemeIdListRequest @@ -14,10 +13,9 @@ class ThemeApiTest : FunSpecSpringbootTest() { context("입력된 모든 ID에 대한 테마를 조회한다.") { test("정상 응답 + 없는 테마가 있으면 생략한다.") { val themeIds: List = initialize("목록 조회를 위한 3개의 테마 생성 및 일부 존재하지 않는 ID 추가") { - val token = testAuthUtil.defaultHqAdminLogin() val themeIds = mutableListOf(INVALID_PK) - (1..3).forEach { - themeIds.add(dummyInitializer.createTheme(token, createRequest.copy(name = "test$it")).id) + (1..3).forEach { _ -> + themeIds.add(dummyInitializer.createTheme().id) } themeIds @@ -41,10 +39,7 @@ class ThemeApiTest : FunSpecSpringbootTest() { context("ID로 테마 정보를 조회한다.") { test("정상 응답") { val createdTheme: ThemeEntity = initialize("조회를 위한 테마 생성") { - dummyInitializer.createTheme( - adminToken = testAuthUtil.defaultHqAdminLogin(), - request = createRequest - ) + dummyInitializer.createTheme() } runTest(