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
|
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
|
import roomescape.util.RoomescapeApiTest
|
||||||
|
|
||||||
class PageControllerTest() : RoomescapeApiTest() {
|
@WebMvcTest(controllers = [
|
||||||
|
AuthPageController::class,
|
||||||
|
AdminPageController::class,
|
||||||
|
ClientPageController::class
|
||||||
|
])
|
||||||
|
class PageControllerTest(
|
||||||
|
@Autowired private val mockMvc: MockMvc
|
||||||
|
) : RoomescapeApiTest() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
listOf("/", "/login").forEach {
|
listOf("/", "/login").forEach {
|
||||||
given("GET $it 요청은") {
|
given("GET $it 요청은") {
|
||||||
`when`("로그인 및 권한 여부와 관계없이 성공한다.") {
|
`when`("로그인 및 권한 여부와 관계없이 성공한다.") {
|
||||||
then("비회원") {
|
then("비회원") {
|
||||||
setUpNotLoggedIn()
|
doNotLogin()
|
||||||
|
|
||||||
runGetTest(it) {
|
runGetTest(
|
||||||
statusCode(200)
|
mockMvc = mockMvc,
|
||||||
|
endpoint = it,
|
||||||
|
log = true
|
||||||
|
) {
|
||||||
|
status { isOk() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
then("회원") {
|
then("회원") {
|
||||||
setUpUser()
|
loginAsUser()
|
||||||
|
|
||||||
runGetTest(it) {
|
runGetTest(
|
||||||
statusCode(200)
|
mockMvc = mockMvc,
|
||||||
|
endpoint = it,
|
||||||
|
log = true
|
||||||
|
) {
|
||||||
|
status { isOk() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
then("관리자") {
|
then("관리자") {
|
||||||
setUpAdmin()
|
loginAsAdmin()
|
||||||
|
|
||||||
runGetTest(it) {
|
runGetTest(
|
||||||
statusCode(200)
|
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 {
|
listOf("/admin", "/admin/reservation", "/admin/time", "/admin/theme", "/admin/waiting").forEach {
|
||||||
given("GET $it 요청을") {
|
given("GET $it 요청을") {
|
||||||
`when`("관리자가 보내면") {
|
`when`("관리자가 보내면") {
|
||||||
setUpAdmin()
|
loginAsAdmin()
|
||||||
|
|
||||||
then("성공한다.") {
|
then("성공한다.") {
|
||||||
runGetTest(it) {
|
runGetTest(
|
||||||
statusCode(200)
|
mockMvc = mockMvc,
|
||||||
|
endpoint = it,
|
||||||
|
log = true
|
||||||
|
) {
|
||||||
|
status { isOk() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
`when`("회원이 보내면") {
|
`when`("회원이 보내면") {
|
||||||
setUpUser()
|
loginAsUser()
|
||||||
|
|
||||||
then("로그인 페이지로 이동한다.") {
|
then("로그인 페이지로 이동한다.") {
|
||||||
runGetTest(it) {
|
runGetTest(
|
||||||
statusCode(200)
|
mockMvc = mockMvc,
|
||||||
body(Matchers.containsString("<title>Login</title>"))
|
endpoint = it,
|
||||||
|
log = true
|
||||||
|
) {
|
||||||
|
status { is3xxRedirection() }
|
||||||
|
header {
|
||||||
|
string("Location", "/login")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,28 +96,42 @@ class PageControllerTest() : RoomescapeApiTest() {
|
|||||||
given("GET $it 요청을") {
|
given("GET $it 요청을") {
|
||||||
`when`("로그인 된 회원이 보내면 성공한다.") {
|
`when`("로그인 된 회원이 보내면 성공한다.") {
|
||||||
then("회원") {
|
then("회원") {
|
||||||
setUpUser()
|
loginAsUser()
|
||||||
|
|
||||||
runGetTest(it) {
|
runGetTest(
|
||||||
statusCode(200)
|
mockMvc = mockMvc,
|
||||||
|
endpoint = it,
|
||||||
|
log = true
|
||||||
|
) {
|
||||||
|
status { isOk() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
then("관리자") {
|
then("관리자") {
|
||||||
setUpAdmin()
|
loginAsAdmin()
|
||||||
|
|
||||||
runGetTest(it) {
|
runGetTest(
|
||||||
statusCode(200)
|
mockMvc = mockMvc,
|
||||||
|
endpoint = it,
|
||||||
|
log = true
|
||||||
|
) {
|
||||||
|
status { isOk() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
`when`("로그인 없이 보내면") {
|
`when`("로그인 없이 보내면") {
|
||||||
then("로그인 페이지로 이동한다.") {
|
then("로그인 페이지로 이동한다.") {
|
||||||
setUpNotLoggedIn()
|
doNotLogin()
|
||||||
|
|
||||||
runGetTest(it) {
|
runGetTest(
|
||||||
statusCode(200)
|
mockMvc = mockMvc,
|
||||||
body(Matchers.containsString("<title>Login</title>"))
|
endpoint = it,
|
||||||
|
log = true
|
||||||
|
) {
|
||||||
|
status { is3xxRedirection() }
|
||||||
|
header {
|
||||||
|
string("Location", "/login")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user