generated from pricelees/issue-pr-template
[#44] 매장 기능 도입 #45
100
src/test/kotlin/roomescape/theme/PublicThemeApiTest.kt
Normal file
100
src/test/kotlin/roomescape/theme/PublicThemeApiTest.kt
Normal file
@ -0,0 +1,100 @@
|
||||
package roomescape.theme
|
||||
|
||||
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
|
||||
|
||||
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 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(
|
||||
using = {
|
||||
body(ThemeIdListRequest(themeIds))
|
||||
},
|
||||
on = {
|
||||
post("/themes/batch")
|
||||
},
|
||||
expect = {
|
||||
statusCode(HttpStatus.OK.value())
|
||||
body("data.themes.size()", equalTo(themeSize))
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
context("ID로 테마 정보를 조회한다.") {
|
||||
test("성공 응답") {
|
||||
val createdTheme: ThemeEntity = dummyInitializer.createTheme(
|
||||
adminToken = testAuthUtil.defaultHqAdminLogin(),
|
||||
request = createRequest
|
||||
)
|
||||
|
||||
runTest(
|
||||
on = {
|
||||
get("/themes/${createdTheme.id}")
|
||||
},
|
||||
expect = {
|
||||
body("data.id", equalTo(createdTheme.id))
|
||||
body("data.name", equalTo(createdTheme.name))
|
||||
assertProperties(
|
||||
props = setOf(
|
||||
"id", "name", "thumbnailUrl", "description", "difficulty", "price",
|
||||
"minParticipants", "maxParticipants",
|
||||
"availableMinutes", "expectedMinutesFrom", "expectedMinutesTo"
|
||||
),
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
test("테마가 없으면 실패한다.") {
|
||||
runExceptionTest(
|
||||
method = HttpMethod.GET,
|
||||
endpoint = "/themes/$INVALID_PK",
|
||||
expectedErrorCode = ThemeErrorCode.THEME_NOT_FOUND
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
src/test/kotlin/roomescape/theme/StoreAdminThemeApiTest.kt
Normal file
61
src/test/kotlin/roomescape/theme/StoreAdminThemeApiTest.kt
Normal file
@ -0,0 +1,61 @@
|
||||
package roomescape.theme
|
||||
|
||||
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.runExceptionTest
|
||||
import roomescape.supports.runTest
|
||||
|
||||
class StoreAdminThemeApiTest : FunSpecSpringbootTest() {
|
||||
init {
|
||||
context("현재 active 상태인 모든 테마의 ID, 이름을 조회한다.") {
|
||||
val endpoint = "/admin/themes/active"
|
||||
|
||||
context("권한이 없으면 접근할 수 없다.") {
|
||||
test("비회원") {
|
||||
runExceptionTest(
|
||||
method = HttpMethod.POST,
|
||||
requestBody = createRequest,
|
||||
endpoint = endpoint,
|
||||
expectedErrorCode = AuthErrorCode.TOKEN_NOT_FOUND
|
||||
)
|
||||
}
|
||||
|
||||
test("회원") {
|
||||
runExceptionTest(
|
||||
token = testAuthUtil.defaultUserLogin(),
|
||||
method = HttpMethod.POST,
|
||||
requestBody = createRequest,
|
||||
endpoint = endpoint,
|
||||
expectedErrorCode = AuthErrorCode.ACCESS_DENIED
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
test("정상 응답") {
|
||||
run {
|
||||
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))
|
||||
}
|
||||
|
||||
runTest(
|
||||
token = testAuthUtil.defaultStoreAdminLogin(),
|
||||
on = {
|
||||
get(endpoint)
|
||||
},
|
||||
expect = {
|
||||
statusCode(200)
|
||||
assertProperties(
|
||||
props = setOf("id", "user", "applicationDateTime", "payment"),
|
||||
propsNameIfList = "themes"
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user