diff --git a/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/controller/betting/BettingControllerTest.kt b/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/controller/betting/BettingControllerTest.kt index 8fc40d7..11c2de6 100644 --- a/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/controller/betting/BettingControllerTest.kt +++ b/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/controller/betting/BettingControllerTest.kt @@ -9,8 +9,6 @@ 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 @@ -28,9 +26,9 @@ class BettingControllerTest : ControllerTestSupport() { mockMvc .perform( post("/v1/betting") - .with(csrf()) - .content(objectMapper.writeValueAsString(request)) - .contentType(MediaType.APPLICATION_JSON) + .withCsrf() + .writeRequestAsContent(request) + .contentTypeAsJson() ) .andDo(::print) .andExpect(status().isCreated()) @@ -48,9 +46,9 @@ class BettingControllerTest : ControllerTestSupport() { mockMvc .perform( post("/v1/betting") - .with(csrf()) - .content(objectMapper.writeValueAsString(request)) - .contentType(MediaType.APPLICATION_JSON) + .withCsrf() + .writeRequestAsContent(request) + .contentTypeAsJson() ) .andDo(::print) .andExpect(status().isBadRequest) @@ -87,9 +85,9 @@ class BettingControllerTest : ControllerTestSupport() { mockMvc .perform( put("/v1/betting") - .with(csrf()) - .content(objectMapper.writeValueAsString(request)) - .contentType(MediaType.APPLICATION_JSON) + .withCsrf() + .writeRequestAsContent(request) + .contentTypeAsJson() ) .andDo(::print) .andExpect(status().isOk) diff --git a/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/controller/goalgifticon/GoalGifticonControllerTest.kt b/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/controller/goalgifticon/GoalGifticonControllerTest.kt new file mode 100644 index 0000000..2fa513c --- /dev/null +++ b/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/controller/goalgifticon/GoalGifticonControllerTest.kt @@ -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())) + } +} \ No newline at end of file