generated from pricelees/issue-pr-template
refactor: 테마 API 테스트에 iniailize inline fun 반영
This commit is contained in:
parent
cc0316d77a
commit
78baa271bb
@ -4,15 +4,15 @@ import io.kotest.matchers.date.shouldBeAfter
|
||||
import io.kotest.matchers.nulls.shouldNotBeNull
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import io.restassured.response.ValidatableResponse
|
||||
import org.hamcrest.CoreMatchers.equalTo
|
||||
import org.hamcrest.CoreMatchers.notNullValue
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.http.HttpMethod
|
||||
import org.springframework.http.HttpStatus
|
||||
import roomescape.admin.infrastructure.persistence.AdminPermissionLevel
|
||||
import roomescape.admin.infrastructure.persistence.AdminType
|
||||
import roomescape.auth.exception.AuthErrorCode
|
||||
import roomescape.supports.*
|
||||
import roomescape.supports.ThemeFixture.createRequest
|
||||
import roomescape.theme.business.MIN_DURATION
|
||||
import roomescape.theme.business.MIN_PARTICIPANTS
|
||||
import roomescape.theme.business.MIN_PRICE
|
||||
@ -20,9 +20,6 @@ import roomescape.theme.exception.ThemeErrorCode
|
||||
import roomescape.theme.infrastructure.persistence.ThemeEntity
|
||||
import roomescape.theme.infrastructure.persistence.ThemeRepository
|
||||
import roomescape.theme.web.ThemeUpdateRequest
|
||||
import roomescape.supports.*
|
||||
import roomescape.supports.ThemeFixture.createRequest
|
||||
import kotlin.random.Random
|
||||
|
||||
class HQAdminThemeApiTest(
|
||||
private val themeRepository: ThemeRepository
|
||||
@ -83,10 +80,8 @@ class HQAdminThemeApiTest(
|
||||
|
||||
|
||||
test("정상 생성 및 감사 정보 확인") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
|
||||
runTest(
|
||||
token = token,
|
||||
token = testAuthUtil.defaultHqAdminLogin(),
|
||||
using = {
|
||||
body(createRequest)
|
||||
},
|
||||
@ -95,7 +90,6 @@ class HQAdminThemeApiTest(
|
||||
},
|
||||
expect = {
|
||||
statusCode(HttpStatus.CREATED.value())
|
||||
body("data.id", notNullValue())
|
||||
}
|
||||
).also {
|
||||
val createdThemeId: Long = it.extract().path("data.id")
|
||||
@ -112,16 +106,15 @@ class HQAdminThemeApiTest(
|
||||
|
||||
test("이미 동일한 이름의 테마가 있으면 실패한다.") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val commonName = "test123"
|
||||
dummyInitializer.createTheme(
|
||||
adminToken = token,
|
||||
request = createRequest.copy(name = commonName)
|
||||
)
|
||||
|
||||
val alreadyExistsName: String = initialize("테스트를 위한 테마 생성 및 이름 반환") {
|
||||
dummyInitializer.createTheme(token, createRequest).name
|
||||
}
|
||||
|
||||
runTest(
|
||||
token = token,
|
||||
using = {
|
||||
body(createRequest.copy(name = commonName))
|
||||
body(createRequest.copy(name = alreadyExistsName))
|
||||
},
|
||||
on = {
|
||||
post(endpoint)
|
||||
@ -151,157 +144,100 @@ class HQAdminThemeApiTest(
|
||||
}
|
||||
|
||||
context("입력된 시간이 ${MIN_DURATION}분 미만이면 실패한다.") {
|
||||
val commonAssertion: ValidatableResponse.() -> Unit = {
|
||||
statusCode(HttpStatus.BAD_REQUEST.value())
|
||||
body("code", equalTo(ThemeErrorCode.DURATION_BELOW_MINIMUM.errorCode))
|
||||
}
|
||||
|
||||
test("field: availableMinutes") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
runTest(
|
||||
token = token,
|
||||
using = {
|
||||
body(createRequest.copy(availableMinutes = (MIN_DURATION - 1).toShort()))
|
||||
},
|
||||
on = {
|
||||
post(endpoint)
|
||||
},
|
||||
expect = commonAssertion
|
||||
runExceptionTest(
|
||||
token = testAuthUtil.defaultHqAdminLogin(),
|
||||
method = HttpMethod.POST,
|
||||
endpoint = endpoint,
|
||||
requestBody = createRequest.copy(availableMinutes = (MIN_DURATION - 1).toShort()),
|
||||
expectedErrorCode = ThemeErrorCode.DURATION_BELOW_MINIMUM
|
||||
)
|
||||
}
|
||||
|
||||
test("field: expectedMinutesFrom") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
runTest(
|
||||
token = token,
|
||||
using = {
|
||||
body(createRequest.copy(expectedMinutesFrom = (MIN_DURATION - 1).toShort()))
|
||||
},
|
||||
on = {
|
||||
post(endpoint)
|
||||
},
|
||||
expect = commonAssertion
|
||||
runExceptionTest(
|
||||
token = testAuthUtil.defaultHqAdminLogin(),
|
||||
method = HttpMethod.POST,
|
||||
endpoint = endpoint,
|
||||
requestBody = createRequest.copy(expectedMinutesFrom = (MIN_DURATION - 1).toShort()),
|
||||
expectedErrorCode = ThemeErrorCode.DURATION_BELOW_MINIMUM
|
||||
)
|
||||
}
|
||||
|
||||
test("field: expectedMinutesTo") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
runTest(
|
||||
token = token,
|
||||
using = {
|
||||
body(createRequest.copy(expectedMinutesTo = (MIN_DURATION - 1).toShort()))
|
||||
},
|
||||
on = {
|
||||
post(endpoint)
|
||||
},
|
||||
expect = commonAssertion
|
||||
runExceptionTest(
|
||||
token = testAuthUtil.defaultHqAdminLogin(),
|
||||
method = HttpMethod.POST,
|
||||
endpoint = endpoint,
|
||||
requestBody = createRequest.copy(expectedMinutesTo = (MIN_DURATION - 1).toShort()),
|
||||
expectedErrorCode = ThemeErrorCode.DURATION_BELOW_MINIMUM
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
context("시간 범위가 잘못 지정되면 실패한다.") {
|
||||
test("최소 예상 시간 > 최대 예상 시간") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
runTest(
|
||||
token = token,
|
||||
using = {
|
||||
body(createRequest.copy(expectedMinutesFrom = 100, expectedMinutesTo = 99))
|
||||
},
|
||||
on = {
|
||||
post(endpoint)
|
||||
},
|
||||
expect = {
|
||||
statusCode(HttpStatus.BAD_REQUEST.value())
|
||||
body("code", equalTo(ThemeErrorCode.MIN_EXPECTED_TIME_EXCEEDS_MAX_EXPECTED_TIME.errorCode))
|
||||
}
|
||||
runExceptionTest(
|
||||
token = testAuthUtil.defaultHqAdminLogin(),
|
||||
method = HttpMethod.POST,
|
||||
endpoint = endpoint,
|
||||
requestBody = createRequest.copy(expectedMinutesFrom = 100, expectedMinutesTo = 99),
|
||||
expectedErrorCode = ThemeErrorCode.MIN_EXPECTED_TIME_EXCEEDS_MAX_EXPECTED_TIME
|
||||
)
|
||||
}
|
||||
|
||||
test("최대 예상 시간 > 이용 가능 시간") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
runTest(
|
||||
token = token,
|
||||
using = {
|
||||
body(
|
||||
createRequest.copy(
|
||||
availableMinutes = 100,
|
||||
expectedMinutesFrom = 101,
|
||||
expectedMinutesTo = 101
|
||||
)
|
||||
)
|
||||
},
|
||||
on = {
|
||||
post(endpoint)
|
||||
},
|
||||
expect = {
|
||||
statusCode(HttpStatus.BAD_REQUEST.value())
|
||||
body("code", equalTo(ThemeErrorCode.EXPECTED_TIME_EXCEEDS_AVAILABLE_TIME.errorCode))
|
||||
}
|
||||
runExceptionTest(
|
||||
token = testAuthUtil.defaultHqAdminLogin(),
|
||||
method = HttpMethod.POST,
|
||||
endpoint = endpoint,
|
||||
requestBody = createRequest.copy(
|
||||
availableMinutes = 100,
|
||||
expectedMinutesFrom = 101,
|
||||
expectedMinutesTo = 101
|
||||
),
|
||||
expectedErrorCode = ThemeErrorCode.EXPECTED_TIME_EXCEEDS_AVAILABLE_TIME
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
context("입력된 인원이 ${MIN_PARTICIPANTS}명 미만이면 실패한다.") {
|
||||
val commonAssertion: ValidatableResponse.() -> Unit = {
|
||||
statusCode(HttpStatus.BAD_REQUEST.value())
|
||||
body("code", equalTo(ThemeErrorCode.PARTICIPANT_BELOW_MINIMUM.errorCode))
|
||||
}
|
||||
|
||||
test("field: minParticipants") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
runTest(
|
||||
token = token,
|
||||
using = {
|
||||
body(createRequest.copy(minParticipants = (MIN_PARTICIPANTS - 1).toShort()))
|
||||
},
|
||||
on = {
|
||||
post(endpoint)
|
||||
},
|
||||
expect = commonAssertion
|
||||
runExceptionTest(
|
||||
token = testAuthUtil.defaultHqAdminLogin(),
|
||||
method = HttpMethod.POST,
|
||||
endpoint = endpoint,
|
||||
requestBody = createRequest.copy(minParticipants = (MIN_PARTICIPANTS - 1).toShort()),
|
||||
expectedErrorCode = ThemeErrorCode.PARTICIPANT_BELOW_MINIMUM
|
||||
)
|
||||
}
|
||||
|
||||
test("field: maxParticipants") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
runTest(
|
||||
token = token,
|
||||
using = {
|
||||
body(createRequest.copy(maxParticipants = (MIN_PARTICIPANTS - 1).toShort()))
|
||||
},
|
||||
on = {
|
||||
post(endpoint)
|
||||
},
|
||||
expect = commonAssertion
|
||||
runExceptionTest(
|
||||
token = testAuthUtil.defaultHqAdminLogin(),
|
||||
method = HttpMethod.POST,
|
||||
endpoint = endpoint,
|
||||
requestBody = createRequest.copy(maxParticipants = (MIN_PARTICIPANTS - 1).toShort()),
|
||||
expectedErrorCode = ThemeErrorCode.PARTICIPANT_BELOW_MINIMUM
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
context("인원 범위가 잘못 지정되면 실패한다.") {
|
||||
test("최소 인원 > 최대 인원") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
runTest(
|
||||
token = token,
|
||||
using = {
|
||||
body(createRequest.copy(minParticipants = 10, maxParticipants = 9))
|
||||
},
|
||||
on = {
|
||||
post(endpoint)
|
||||
},
|
||||
expect = {
|
||||
statusCode(HttpStatus.BAD_REQUEST.value())
|
||||
body("code", equalTo(ThemeErrorCode.MIN_PARTICIPANT_EXCEEDS_MAX_PARTICIPANT.errorCode))
|
||||
}
|
||||
runExceptionTest(
|
||||
token = testAuthUtil.defaultHqAdminLogin(),
|
||||
method = HttpMethod.POST,
|
||||
endpoint = endpoint,
|
||||
requestBody = createRequest.copy(minParticipants = 10, maxParticipants = 9),
|
||||
expectedErrorCode = ThemeErrorCode.MIN_PARTICIPANT_EXCEEDS_MAX_PARTICIPANT
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context("관리자가 모든 테마를 조회한다.") {
|
||||
context("테마 요약 목록을 조회한다.") {
|
||||
val endpoint = "/admin/themes"
|
||||
val requests = listOf(
|
||||
createRequest.copy(name = "open", isActive = true),
|
||||
createRequest.copy(name = "close", isActive = false)
|
||||
)
|
||||
|
||||
context("권한이 없으면 접근할 수 없다.") {
|
||||
test("비회원") {
|
||||
@ -337,17 +273,24 @@ class HQAdminThemeApiTest(
|
||||
}
|
||||
|
||||
|
||||
test("비공개 테마까지 포함하여 간단한 정보만 조회된다.") {
|
||||
test("정상 응답") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
requests.forEach { dummyInitializer.createTheme(token, it) }
|
||||
|
||||
val themes: List<ThemeEntity> = 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))
|
||||
)
|
||||
}
|
||||
|
||||
runTest(
|
||||
token = token,
|
||||
on = {
|
||||
get("/admin/themes")
|
||||
get(endpoint)
|
||||
},
|
||||
expect = {
|
||||
body("data.themes.size()", equalTo(requests.size))
|
||||
body("data.themes.size()", equalTo(themes.size))
|
||||
assertProperties(
|
||||
props = setOf("id", "name", "difficulty", "price", "isActive"),
|
||||
propsNameIfList = "themes",
|
||||
@ -407,10 +350,9 @@ class HQAdminThemeApiTest(
|
||||
|
||||
test("정상 응답") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme = dummyInitializer.createTheme(
|
||||
adminToken = token,
|
||||
request = createRequest
|
||||
)
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
runTest(
|
||||
token = token,
|
||||
@ -492,10 +434,9 @@ class HQAdminThemeApiTest(
|
||||
|
||||
test("정상 삭제") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme = dummyInitializer.createTheme(
|
||||
adminToken = token,
|
||||
request = createRequest
|
||||
)
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
runTest(
|
||||
token = token,
|
||||
@ -576,13 +517,15 @@ class HQAdminThemeApiTest(
|
||||
val updateRequest = ThemeUpdateRequest(name = "modified")
|
||||
|
||||
test("정상 수정 및 감사 정보 변경 확인") {
|
||||
val createdTheme: ThemeEntity = dummyInitializer.createTheme(
|
||||
adminToken = testAuthUtil.defaultHqAdminLogin(),
|
||||
request = createRequest.copy(name = "theme-${Random.nextInt()}")
|
||||
)
|
||||
val otherAdminToken: String = testAuthUtil.adminLogin(
|
||||
AdminFixture.createHqAdmin(permissionLevel = AdminPermissionLevel.WRITABLE)
|
||||
)
|
||||
val createdTheme = initialize("테스트를 위한 관리자1의 테마 생성") {
|
||||
dummyInitializer.createTheme(testAuthUtil.defaultHqAdminLogin(), createRequest)
|
||||
}
|
||||
|
||||
val otherAdminToken: String = initialize("감사 정보 변경 확인을 위한 관리자2 로그인") {
|
||||
testAuthUtil.adminLogin(
|
||||
AdminFixture.createHqAdmin(permissionLevel = AdminPermissionLevel.WRITABLE)
|
||||
)
|
||||
}
|
||||
|
||||
runTest(
|
||||
token = otherAdminToken,
|
||||
@ -606,13 +549,14 @@ class HQAdminThemeApiTest(
|
||||
}
|
||||
|
||||
test("입력값이 없으면 수정하지 않는다.") {
|
||||
val createdTheme: ThemeEntity = dummyInitializer.createTheme(
|
||||
adminToken = testAuthUtil.defaultHqAdminLogin(),
|
||||
request = createRequest.copy(name = "theme-${Random.nextInt()}")
|
||||
)
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
runTest(
|
||||
token = testAuthUtil.defaultHqAdminLogin(),
|
||||
token = token,
|
||||
using = {
|
||||
body(ThemeUpdateRequest())
|
||||
},
|
||||
@ -641,14 +585,13 @@ class HQAdminThemeApiTest(
|
||||
}
|
||||
|
||||
test("금액이 ${MIN_PRICE}원 미만이면 실패한다.") {
|
||||
val adminToken = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme: ThemeEntity = dummyInitializer.createTheme(
|
||||
adminToken = adminToken,
|
||||
request = createRequest.copy(name = "theme-${Random.nextInt()}")
|
||||
)
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
runExceptionTest(
|
||||
token = adminToken,
|
||||
token = token,
|
||||
method = HttpMethod.PATCH,
|
||||
endpoint = "/admin/themes/${createdTheme.id}",
|
||||
requestBody = updateRequest.copy(price = (MIN_PRICE - 1)),
|
||||
@ -657,20 +600,14 @@ class HQAdminThemeApiTest(
|
||||
}
|
||||
|
||||
context("입력된 시간이 ${MIN_DURATION}분 미만이면 실패한다.") {
|
||||
lateinit var adminToken: String
|
||||
lateinit var createdTheme: ThemeEntity
|
||||
|
||||
beforeTest {
|
||||
adminToken = testAuthUtil.defaultHqAdminLogin()
|
||||
createdTheme = dummyInitializer.createTheme(
|
||||
adminToken = adminToken,
|
||||
request = createRequest.copy(name = "theme-${Random.nextInt()}")
|
||||
)
|
||||
}
|
||||
|
||||
test("field: availableMinutes") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
runExceptionTest(
|
||||
token = adminToken,
|
||||
token = token,
|
||||
method = HttpMethod.PATCH,
|
||||
endpoint = "/admin/themes/${createdTheme.id}",
|
||||
requestBody = updateRequest.copy(availableMinutes = (MIN_DURATION - 1).toShort()),
|
||||
@ -679,8 +616,13 @@ class HQAdminThemeApiTest(
|
||||
}
|
||||
|
||||
test("field: expectedMinutesFrom") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
runExceptionTest(
|
||||
token = adminToken,
|
||||
token = token,
|
||||
method = HttpMethod.PATCH,
|
||||
endpoint = "/admin/themes/${createdTheme.id}",
|
||||
requestBody = updateRequest.copy(expectedMinutesFrom = (MIN_DURATION - 1).toShort()),
|
||||
@ -689,8 +631,13 @@ class HQAdminThemeApiTest(
|
||||
}
|
||||
|
||||
test("field: expectedMinutesTo") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
runExceptionTest(
|
||||
token = adminToken,
|
||||
token = token,
|
||||
method = HttpMethod.PATCH,
|
||||
endpoint = "/admin/themes/${createdTheme.id}",
|
||||
requestBody = updateRequest.copy(expectedMinutesTo = (MIN_DURATION - 1).toShort()),
|
||||
@ -700,20 +647,14 @@ class HQAdminThemeApiTest(
|
||||
}
|
||||
|
||||
context("시간 범위가 잘못 지정되면 실패한다.") {
|
||||
lateinit var adminToken: String
|
||||
lateinit var createdTheme: ThemeEntity
|
||||
|
||||
beforeTest {
|
||||
adminToken = testAuthUtil.defaultHqAdminLogin()
|
||||
createdTheme = dummyInitializer.createTheme(
|
||||
adminToken = adminToken,
|
||||
request = createRequest.copy(name = "theme-${Random.nextInt()}")
|
||||
)
|
||||
}
|
||||
|
||||
test("최소 예상 시간 > 최대 예상 시간") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
runExceptionTest(
|
||||
token = adminToken,
|
||||
token = token,
|
||||
method = HttpMethod.PATCH,
|
||||
endpoint = "/admin/themes/${createdTheme.id}",
|
||||
requestBody = updateRequest.copy(expectedMinutesFrom = 100, expectedMinutesTo = 99),
|
||||
@ -723,17 +664,22 @@ class HQAdminThemeApiTest(
|
||||
|
||||
|
||||
test("최대 예상 시간 > 이용 가능 시간") {
|
||||
val body = updateRequest.copy(
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
val requestBody = updateRequest.copy(
|
||||
availableMinutes = 100,
|
||||
expectedMinutesFrom = 101,
|
||||
expectedMinutesTo = 101
|
||||
)
|
||||
|
||||
runExceptionTest(
|
||||
token = adminToken,
|
||||
token = token,
|
||||
method = HttpMethod.PATCH,
|
||||
endpoint = "/admin/themes/${createdTheme.id}",
|
||||
requestBody = body,
|
||||
requestBody = requestBody,
|
||||
expectedErrorCode = ThemeErrorCode.EXPECTED_TIME_EXCEEDS_AVAILABLE_TIME
|
||||
)
|
||||
}
|
||||
@ -741,20 +687,14 @@ class HQAdminThemeApiTest(
|
||||
|
||||
|
||||
context("입력된 인원이 ${MIN_PARTICIPANTS}명 미만이면 실패한다.") {
|
||||
lateinit var adminToken: String
|
||||
lateinit var createdTheme: ThemeEntity
|
||||
|
||||
beforeTest {
|
||||
adminToken = testAuthUtil.defaultHqAdminLogin()
|
||||
createdTheme = dummyInitializer.createTheme(
|
||||
adminToken = adminToken,
|
||||
request = createRequest.copy(name = "theme-${Random.nextInt()}")
|
||||
)
|
||||
}
|
||||
|
||||
test("field: minParticipants") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
runExceptionTest(
|
||||
token = adminToken,
|
||||
token = token,
|
||||
method = HttpMethod.PATCH,
|
||||
endpoint = "/admin/themes/${createdTheme.id}",
|
||||
requestBody = updateRequest.copy(minParticipants = (MIN_PARTICIPANTS - 1).toShort()),
|
||||
@ -763,8 +703,13 @@ class HQAdminThemeApiTest(
|
||||
}
|
||||
|
||||
test("field: maxParticipants") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
runExceptionTest(
|
||||
token = adminToken,
|
||||
token = token,
|
||||
method = HttpMethod.PATCH,
|
||||
endpoint = "/admin/themes/${createdTheme.id}",
|
||||
requestBody = updateRequest.copy(maxParticipants = (MIN_PARTICIPANTS - 1).toShort()),
|
||||
@ -774,20 +719,14 @@ class HQAdminThemeApiTest(
|
||||
}
|
||||
|
||||
context("인원 범위가 잘못 지정되면 실패한다.") {
|
||||
lateinit var adminToken: String
|
||||
lateinit var createdTheme: ThemeEntity
|
||||
|
||||
beforeTest {
|
||||
adminToken = testAuthUtil.defaultHqAdminLogin()
|
||||
createdTheme = dummyInitializer.createTheme(
|
||||
adminToken = adminToken,
|
||||
request = createRequest.copy(name = "theme-${Random.nextInt()}")
|
||||
)
|
||||
}
|
||||
|
||||
test("최소 인원 > 최대 인원") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val createdTheme = initialize("테스트를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(token, createRequest)
|
||||
}
|
||||
|
||||
runExceptionTest(
|
||||
token = adminToken,
|
||||
token = token,
|
||||
method = HttpMethod.PATCH,
|
||||
endpoint = "/admin/themes/${createdTheme.id}",
|
||||
requestBody = updateRequest.copy(minParticipants = 10, maxParticipants = 9),
|
||||
|
||||
@ -12,41 +12,17 @@ import roomescape.theme.web.ThemeIdListRequest
|
||||
class PublicThemeApiTest : FunSpecSpringbootTest() {
|
||||
init {
|
||||
context("입력된 모든 ID에 대한 테마를 조회한다.") {
|
||||
test("정상 응답") {
|
||||
val adminToken = testAuthUtil.defaultHqAdminLogin()
|
||||
val themeSize = 3
|
||||
val themeIds = mutableListOf<Long>()
|
||||
|
||||
for (i in 1..themeSize) {
|
||||
dummyInitializer.createTheme(adminToken, createRequest.copy(name = "test$i"))
|
||||
.also { themeIds.add(it.id) }
|
||||
}
|
||||
|
||||
runTest(
|
||||
using = {
|
||||
body(ThemeIdListRequest(themeIds))
|
||||
},
|
||||
on = {
|
||||
post("/themes/batch")
|
||||
},
|
||||
expect = {
|
||||
statusCode(HttpStatus.OK.value())
|
||||
body("data.themes.size()", equalTo(themeSize))
|
||||
test("정상 응답 + 없는 테마가 있으면 생략한다.") {
|
||||
val themeIds: List<Long> = 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)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
test("없는 테마가 있으면 생략한다.") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
val themeSize = 3
|
||||
val themeIds = mutableListOf<Long>()
|
||||
|
||||
for (i in 1..themeSize) {
|
||||
dummyInitializer.createTheme(token, createRequest.copy(name = "test$i"))
|
||||
.also { themeIds.add(it.id) }
|
||||
themeIds
|
||||
}
|
||||
|
||||
themeIds.add(INVALID_PK)
|
||||
runTest(
|
||||
using = {
|
||||
body(ThemeIdListRequest(themeIds))
|
||||
@ -56,7 +32,7 @@ class PublicThemeApiTest : FunSpecSpringbootTest() {
|
||||
},
|
||||
expect = {
|
||||
statusCode(HttpStatus.OK.value())
|
||||
body("data.themes.size()", equalTo(themeSize))
|
||||
body("data.themes.size()", equalTo(themeIds.filter { it != INVALID_PK }.size))
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -64,11 +40,13 @@ class PublicThemeApiTest : FunSpecSpringbootTest() {
|
||||
|
||||
|
||||
context("ID로 테마 정보를 조회한다.") {
|
||||
test("성공 응답") {
|
||||
val createdTheme: ThemeEntity = dummyInitializer.createTheme(
|
||||
adminToken = testAuthUtil.defaultHqAdminLogin(),
|
||||
request = createRequest
|
||||
)
|
||||
test("정상 응답") {
|
||||
val createdTheme: ThemeEntity = initialize("조회를 위한 테마 생성") {
|
||||
dummyInitializer.createTheme(
|
||||
adminToken = testAuthUtil.defaultHqAdminLogin(),
|
||||
request = createRequest
|
||||
)
|
||||
}
|
||||
|
||||
runTest(
|
||||
on = {
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
package roomescape.theme
|
||||
|
||||
import org.hamcrest.CoreMatchers.equalTo
|
||||
import org.springframework.http.HttpMethod
|
||||
import roomescape.auth.exception.AuthErrorCode
|
||||
import roomescape.supports.FunSpecSpringbootTest
|
||||
import roomescape.supports.ThemeFixture.createRequest
|
||||
import roomescape.supports.assertProperties
|
||||
import roomescape.supports.initialize
|
||||
import roomescape.supports.runExceptionTest
|
||||
import roomescape.supports.runTest
|
||||
|
||||
@ -16,7 +18,7 @@ class StoreAdminThemeApiTest : FunSpecSpringbootTest() {
|
||||
context("권한이 없으면 접근할 수 없다.") {
|
||||
test("비회원") {
|
||||
runExceptionTest(
|
||||
method = HttpMethod.POST,
|
||||
method = HttpMethod.GET,
|
||||
requestBody = createRequest,
|
||||
endpoint = endpoint,
|
||||
expectedErrorCode = AuthErrorCode.TOKEN_NOT_FOUND
|
||||
@ -26,7 +28,7 @@ class StoreAdminThemeApiTest : FunSpecSpringbootTest() {
|
||||
test("회원") {
|
||||
runExceptionTest(
|
||||
token = testAuthUtil.defaultUserLogin(),
|
||||
method = HttpMethod.POST,
|
||||
method = HttpMethod.GET,
|
||||
requestBody = createRequest,
|
||||
endpoint = endpoint,
|
||||
expectedErrorCode = AuthErrorCode.ACCESS_DENIED
|
||||
@ -35,11 +37,14 @@ class StoreAdminThemeApiTest : FunSpecSpringbootTest() {
|
||||
}
|
||||
|
||||
test("정상 응답") {
|
||||
run {
|
||||
val createdThemes = initialize("Active 상태 테마 2개 / Inactive 상태 테마 1개 생성") {
|
||||
val token = testAuthUtil.defaultHqAdminLogin()
|
||||
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))
|
||||
|
||||
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))
|
||||
)
|
||||
}
|
||||
|
||||
runTest(
|
||||
@ -49,8 +54,9 @@ class StoreAdminThemeApiTest : FunSpecSpringbootTest() {
|
||||
},
|
||||
expect = {
|
||||
statusCode(200)
|
||||
body("data.themes.size()", equalTo(createdThemes.filter { it.isActive }.size))
|
||||
assertProperties(
|
||||
props = setOf("id", "user", "applicationDateTime", "payment"),
|
||||
props = setOf("id", "name"),
|
||||
propsNameIfList = "themes"
|
||||
)
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user