-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from whatever-mentoring/feature/goal-gifticon-…
…controller-test Write test codes of GoalGifticonController
- Loading branch information
Showing
6 changed files
with
109 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...est/kotlin/com/whatever/raisedragon/controller/goalgifticon/GoalGifticonControllerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.whatever.raisedragon.controller.goalgifticon | ||
|
||
import com.whatever.raisedragon.ControllerTestSupport | ||
import com.whatever.raisedragon.security.WithCustomUser | ||
import org.hamcrest.core.IsNull.nullValue | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
|
||
@WithCustomUser(id = 1L, nickname = "User") | ||
class GoalGifticonControllerTest : ControllerTestSupport() { | ||
|
||
@DisplayName("GoalGifticon을 생성한다.") | ||
@Test | ||
fun create() { | ||
// given | ||
val gifticonUrl = "www.sample.com/gifticon" | ||
val request = GoalGifticonCreateRequest(goalId = 1L, gifticonURL = gifticonUrl) | ||
|
||
// when // then | ||
mockMvc | ||
.perform( | ||
post("/v1/goal-gifticon") | ||
.withCsrf() | ||
.writeRequestAsContent(request) | ||
.contentTypeAsJson() | ||
) | ||
.andDo(::print) | ||
.andExpect(status().isCreated) | ||
.andExpect(jsonPath("$.isSuccess").value(true)) | ||
.andExpect(jsonPath("$.errorResponse").value(nullValue())) | ||
} | ||
|
||
@DisplayName("다짐 내 GoalGifticon을 조회한다.") | ||
@Test | ||
fun retrieve() { | ||
// given | ||
val goalId = 1L | ||
|
||
// when // then | ||
mockMvc | ||
.perform( | ||
get("/v1/goal-gifticon/$goalId") | ||
) | ||
.andDo(::print) | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$.isSuccess").value(true)) | ||
.andExpect(jsonPath("$.errorResponse").value(nullValue())) | ||
} | ||
|
||
@DisplayName("다짐 내 기프티콘을 수정한다.") | ||
@Test | ||
fun update() { | ||
// given | ||
val gifticonUrl = "www.sample.com/updated-gifticon" | ||
val request = GoalGifticonRequest(goalId = 1L, gifticonURL = gifticonUrl) | ||
|
||
// when // then | ||
mockMvc | ||
.perform( | ||
post("/v1/goal-gifticon") | ||
.withCsrf() | ||
.writeRequestAsContent(request) | ||
.contentTypeAsJson() | ||
) | ||
.andDo(::print) | ||
.andExpect(jsonPath("$.isSuccess").value(true)) | ||
.andExpect(jsonPath("$.errorResponse").value(nullValue())) | ||
} | ||
} |