generated from pricelees/issue-pr-template
68 lines
2.6 KiB
Kotlin
68 lines
2.6 KiB
Kotlin
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
|
|
|
|
class StoreAdminThemeApiTest : FunSpecSpringbootTest() {
|
|
init {
|
|
context("현재 active 상태인 모든 테마의 ID, 이름을 조회한다.") {
|
|
val endpoint = "/admin/themes/active"
|
|
|
|
context("권한이 없으면 접근할 수 없다.") {
|
|
test("비회원") {
|
|
runExceptionTest(
|
|
method = HttpMethod.GET,
|
|
requestBody = createRequest,
|
|
endpoint = endpoint,
|
|
expectedErrorCode = AuthErrorCode.TOKEN_NOT_FOUND
|
|
)
|
|
}
|
|
|
|
test("회원") {
|
|
runExceptionTest(
|
|
token = testAuthUtil.defaultUserLogin(),
|
|
method = HttpMethod.GET,
|
|
requestBody = createRequest,
|
|
endpoint = endpoint,
|
|
expectedErrorCode = AuthErrorCode.ACCESS_DENIED
|
|
)
|
|
}
|
|
}
|
|
|
|
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))
|
|
)
|
|
}
|
|
|
|
runTest(
|
|
token = testAuthUtil.defaultStoreAdminLogin(),
|
|
on = {
|
|
get(endpoint)
|
|
},
|
|
expect = {
|
|
statusCode(200)
|
|
body("data.themes.size()", equalTo(createdThemes.filter { it.isActive }.size))
|
|
assertProperties(
|
|
props = setOf("id", "name"),
|
|
propsNameIfList = "themes"
|
|
)
|
|
},
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|