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