-
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 #87 from whatever-mentoring/feature/betting-contro…
…ller-test Write test code of BettingController
- Loading branch information
Showing
4 changed files
with
106 additions
and
1 deletion.
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
1 change: 0 additions & 1 deletion
1
...agon-api/src/main/kotlin/com/whatever/raisedragon/controller/betting/BettingController.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
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
99 changes: 99 additions & 0 deletions
99
...-api/src/test/kotlin/com/whatever/raisedragon/controller/betting/BettingControllerTest.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,99 @@ | ||
package com.whatever.raisedragon.controller.betting | ||
|
||
import com.whatever.raisedragon.ControllerTestSupport | ||
import com.whatever.raisedragon.domain.betting.BettingPredictionType | ||
import com.whatever.raisedragon.security.WithCustomUser | ||
import org.assertj.core.api.Assertions.* | ||
import org.hamcrest.core.IsNull.notNullValue | ||
import org.hamcrest.core.IsNull.nullValue | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.Mockito.* | ||
import org.springframework.http.MediaType | ||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.* | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
|
||
@WithCustomUser(id = 1L, nickname = "User") | ||
class BettingControllerTest : ControllerTestSupport() { | ||
|
||
@DisplayName("Betting을 생성한다.") | ||
@Test | ||
fun create1() { | ||
// given | ||
val request = BettingCreateRequest(goalId = 1L, predictionType = BettingPredictionType.FAIL) | ||
|
||
// when // then | ||
mockMvc | ||
.perform( | ||
post("/v1/betting") | ||
.with(csrf()) | ||
.content(objectMapper.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
) | ||
.andDo(::print) | ||
.andExpect(status().isCreated()) | ||
.andExpect(jsonPath("$.isSuccess").value(true)) | ||
.andExpect(jsonPath("$.errorResponse").value(nullValue())) | ||
} | ||
|
||
@DisplayName("Betting을 생성할 때 goalId는 양수이다.") | ||
@Test | ||
fun create2() { | ||
// given | ||
val request = BettingCreateRequest(goalId = -1, predictionType = BettingPredictionType.FAIL) | ||
|
||
// when // then | ||
mockMvc | ||
.perform( | ||
post("/v1/betting") | ||
.with(csrf()) | ||
.content(objectMapper.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
) | ||
.andDo(::print) | ||
.andExpect(status().isBadRequest) | ||
.andExpect(jsonPath("$.isSuccess").value(false)) | ||
.andExpect(jsonPath("$.errorResponse").value(notNullValue())) | ||
.andExpect(jsonPath("$.errorResponse.detailMessage").value("올바른 goalId를 입력해야합니다.")) | ||
.andExpect(jsonPath("$.data").isEmpty) | ||
} | ||
|
||
@DisplayName("단건 베팅을 조회합니다.") | ||
@Test | ||
fun retrieve() { | ||
// given | ||
val bettingId = 1L | ||
|
||
// when // then | ||
mockMvc | ||
.perform( | ||
get("/v1/betting/$bettingId") | ||
) | ||
.andDo(::print) | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$.isSuccess").value(true)) | ||
.andExpect(jsonPath("$.errorResponse").value(nullValue())) | ||
} | ||
|
||
@DisplayName("베팅을 업데이트 합니다.") | ||
@Test | ||
fun update() { | ||
// given | ||
val request = BettingUpdateRequest(bettingId = 1L, predictionType = BettingPredictionType.SUCCESS) | ||
|
||
// when // then | ||
mockMvc | ||
.perform( | ||
put("/v1/betting") | ||
.with(csrf()) | ||
.content(objectMapper.writeValueAsString(request)) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
) | ||
.andDo(::print) | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$.isSuccess").value(true)) | ||
.andExpect(jsonPath("$.errorResponse").value(nullValue())) | ||
} | ||
} |