generated from pricelees/issue-pr-template
refactor: 새로 정의한 API 테스트 클래스를 바탕으로 PageControllerTest 수정
This commit is contained in:
parent
be9a6bc80e
commit
e942d772dc
@ -1,35 +1,56 @@
|
||||
package roomescape.view
|
||||
|
||||
import org.hamcrest.Matchers
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||
import org.springframework.test.web.servlet.MockMvc
|
||||
import roomescape.util.RoomescapeApiTest
|
||||
|
||||
class PageControllerTest() : RoomescapeApiTest() {
|
||||
@WebMvcTest(controllers = [
|
||||
AuthPageController::class,
|
||||
AdminPageController::class,
|
||||
ClientPageController::class
|
||||
])
|
||||
class PageControllerTest(
|
||||
@Autowired private val mockMvc: MockMvc
|
||||
) : RoomescapeApiTest() {
|
||||
|
||||
init {
|
||||
listOf("/", "/login").forEach {
|
||||
given("GET $it 요청은") {
|
||||
`when`("로그인 및 권한 여부와 관계없이 성공한다.") {
|
||||
then("비회원") {
|
||||
setUpNotLoggedIn()
|
||||
doNotLogin()
|
||||
|
||||
runGetTest(it) {
|
||||
statusCode(200)
|
||||
runGetTest(
|
||||
mockMvc = mockMvc,
|
||||
endpoint = it,
|
||||
log = true
|
||||
) {
|
||||
status { isOk() }
|
||||
}
|
||||
}
|
||||
|
||||
then("회원") {
|
||||
setUpUser()
|
||||
loginAsUser()
|
||||
|
||||
runGetTest(it) {
|
||||
statusCode(200)
|
||||
runGetTest(
|
||||
mockMvc = mockMvc,
|
||||
endpoint = it,
|
||||
log = true
|
||||
) {
|
||||
status { isOk() }
|
||||
}
|
||||
}
|
||||
|
||||
then("관리자") {
|
||||
setUpAdmin()
|
||||
loginAsAdmin()
|
||||
|
||||
runGetTest(it) {
|
||||
statusCode(200)
|
||||
runGetTest(
|
||||
mockMvc = mockMvc,
|
||||
endpoint = it,
|
||||
log = true
|
||||
) {
|
||||
status { isOk() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -39,22 +60,32 @@ class PageControllerTest() : RoomescapeApiTest() {
|
||||
listOf("/admin", "/admin/reservation", "/admin/time", "/admin/theme", "/admin/waiting").forEach {
|
||||
given("GET $it 요청을") {
|
||||
`when`("관리자가 보내면") {
|
||||
setUpAdmin()
|
||||
loginAsAdmin()
|
||||
|
||||
then("성공한다.") {
|
||||
runGetTest(it) {
|
||||
statusCode(200)
|
||||
runGetTest(
|
||||
mockMvc = mockMvc,
|
||||
endpoint = it,
|
||||
log = true
|
||||
) {
|
||||
status { isOk() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
`when`("회원이 보내면") {
|
||||
setUpUser()
|
||||
loginAsUser()
|
||||
|
||||
then("로그인 페이지로 이동한다.") {
|
||||
runGetTest(it) {
|
||||
statusCode(200)
|
||||
body(Matchers.containsString("<title>Login</title>"))
|
||||
runGetTest(
|
||||
mockMvc = mockMvc,
|
||||
endpoint = it,
|
||||
log = true
|
||||
) {
|
||||
status { is3xxRedirection() }
|
||||
header {
|
||||
string("Location", "/login")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,28 +96,42 @@ class PageControllerTest() : RoomescapeApiTest() {
|
||||
given("GET $it 요청을") {
|
||||
`when`("로그인 된 회원이 보내면 성공한다.") {
|
||||
then("회원") {
|
||||
setUpUser()
|
||||
loginAsUser()
|
||||
|
||||
runGetTest(it) {
|
||||
statusCode(200)
|
||||
runGetTest(
|
||||
mockMvc = mockMvc,
|
||||
endpoint = it,
|
||||
log = true
|
||||
) {
|
||||
status { isOk() }
|
||||
}
|
||||
}
|
||||
then("관리자") {
|
||||
setUpAdmin()
|
||||
loginAsAdmin()
|
||||
|
||||
runGetTest(it) {
|
||||
statusCode(200)
|
||||
runGetTest(
|
||||
mockMvc = mockMvc,
|
||||
endpoint = it,
|
||||
log = true
|
||||
) {
|
||||
status { isOk() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
`when`("로그인 없이 보내면") {
|
||||
then("로그인 페이지로 이동한다.") {
|
||||
setUpNotLoggedIn()
|
||||
doNotLogin()
|
||||
|
||||
runGetTest(it) {
|
||||
statusCode(200)
|
||||
body(Matchers.containsString("<title>Login</title>"))
|
||||
runGetTest(
|
||||
mockMvc = mockMvc,
|
||||
endpoint = it,
|
||||
log = true
|
||||
) {
|
||||
status { is3xxRedirection() }
|
||||
header {
|
||||
string("Location", "/login")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user