-
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 branch 'develop' into fix/101-change-timeline-cursor
- Loading branch information
Showing
12 changed files
with
478 additions
and
19 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
29 changes: 29 additions & 0 deletions
29
module-presentation/src/test/java/com/depromeet/memory/config/ControllerTestConfig.java
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,29 @@ | ||
package com.depromeet.memory.config; | ||
|
||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*; | ||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
@SpringJUnitWebConfig | ||
public abstract class ControllerTestConfig { | ||
@Autowired protected WebApplicationContext webApplicationContext; | ||
protected MockMvc mockMvc; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
this.mockMvc = | ||
MockMvcBuilders.webAppContextSetup(webApplicationContext) | ||
.apply(springSecurity()) | ||
.defaultRequest(post("/**").with(csrf())) | ||
.defaultRequest(patch("/**").with(csrf())) | ||
.defaultRequest(delete("/**").with(csrf())) | ||
.build(); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
module-presentation/src/test/java/com/depromeet/memory/controller/MemoryControllerTest.java
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,116 @@ | ||
package com.depromeet.memory.controller; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import com.depromeet.memory.api.MemoryController; | ||
import com.depromeet.memory.config.ControllerTestConfig; | ||
import com.depromeet.memory.facade.MemoryFacade; | ||
import com.depromeet.memory.mock.WithCustomMockMember; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
|
||
@WebMvcTest(MemoryController.class) | ||
public class MemoryControllerTest extends ControllerTestConfig { | ||
@Autowired private ObjectMapper objectMapper; | ||
|
||
@MockBean MemoryFacade memoryFacade; | ||
|
||
@Test | ||
@WithCustomMockMember | ||
void ์์๊ธฐ๋ก์_์์ฑํฉ๋๋ค() throws Exception { | ||
Map<String, Object> requestBody = new HashMap<>(); | ||
requestBody.put("poolId", 1); | ||
requestBody.put("item", "์ค๋ฆฌ๋ฐ"); | ||
requestBody.put("heartRate", 115); | ||
requestBody.put("pace", "05:00:00"); | ||
requestBody.put("kcal", 300); | ||
requestBody.put("recordAt", "2024-07-24"); | ||
requestBody.put("startTime", "11:00:00"); | ||
requestBody.put("endTime", "11:50:00"); | ||
requestBody.put("lane", 25); | ||
requestBody.put("diary", "์ผ๊ธฐ๋ฅผ ๊ธฐ๋กํ๋ค"); | ||
|
||
List<Map<String, Object>> strokes = new ArrayList<>(); | ||
Map<String, Object> stroke = new HashMap<>(); | ||
stroke.put("name", "์์ ํ"); | ||
stroke.put("laps", 3); | ||
stroke.put("meter", 150); | ||
strokes.add(stroke); | ||
|
||
requestBody.put("strokes", strokes); | ||
|
||
List<Long> imageIdList = new ArrayList<>(); | ||
requestBody.put("imageIdList", imageIdList); | ||
|
||
mockMvc.perform( | ||
post("/api/memory") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(requestBody))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.code").value("MEMORY_1")) | ||
.andExpect(jsonPath("$.message").value("์์ ๊ธฐ๋ก ์ ์ฅ์ ์ฑ๊ณตํ์์ต๋๋ค")) | ||
.andDo(print()); | ||
} | ||
|
||
@Test | ||
@WithCustomMockMember | ||
public void ์์๊ธฐ๋ก์_์กฐํํฉ๋๋ค() throws Exception { | ||
mockMvc.perform(get("/api/memory/{memoryId}", 1)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.code").value("MEMORY_2")) | ||
.andExpect(jsonPath("$.message").value("์์ ๊ธฐ๋ก ์กฐํ์ ์ฑ๊ณตํ์์ต๋๋ค")) | ||
.andDo(print()); | ||
} | ||
|
||
@Test | ||
@WithCustomMockMember | ||
public void ์์๊ธฐ๋ก์_๊ฐฑ์ ํฉ๋๋ค() throws Exception { | ||
Map<String, Object> requestBody = new HashMap<>(); | ||
requestBody.put("poolId", 1); | ||
requestBody.put("recordAt", "2024-07-24"); | ||
requestBody.put("startTime", "11:00:00"); | ||
requestBody.put("endTime", "11:50:00"); | ||
mockMvc.perform( | ||
patch("/api/memory/{memoryId}", 1) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(requestBody))) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.code").value("MEMORY_3")) | ||
.andExpect(jsonPath("$.message").value("์์ ๊ธฐ๋ก ์์ ์ ์ฑ๊ณตํ์์ต๋๋ค")) | ||
.andDo(print()); | ||
} | ||
|
||
@Test | ||
@WithCustomMockMember | ||
public void ์์๊ธฐ๋ก_ํ์๋ผ์ธ์_์กฐํํฉ๋๋ค() throws Exception { | ||
mockMvc.perform( | ||
get("/api/memory/timeline") | ||
.param("cursorId", "1L") | ||
.param("date", "2024-07") | ||
.param("size", "5")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.code").value("MEMORY_4")) | ||
.andExpect(jsonPath("$.message").value("ํ์๋ผ์ธ ์กฐํ์ ์ฑ๊ณตํ์์ต๋๋ค")) | ||
.andDo(print()); | ||
} | ||
|
||
@Test | ||
@WithCustomMockMember | ||
public void ์์๊ธฐ๋ก_์บ๋ฆฐ๋๋ฅผ_์กฐํํฉ๋๋ค() throws Exception { | ||
mockMvc.perform(get("/api/memory/calendar").param("yearMonth", "2024-07")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.code").value("MEMORY_5")) | ||
.andExpect(jsonPath("$.message").value("์บ๋ฆฐ๋ ์กฐํ์ ์ฑ๊ณตํ์์ต๋๋ค")) | ||
.andDo(print()); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
module-presentation/src/test/java/com/depromeet/memory/controller/PoolControllerTest.java
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,77 @@ | ||
package com.depromeet.memory.controller; | ||
|
||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import com.depromeet.memory.config.ControllerTestConfig; | ||
import com.depromeet.memory.mock.WithCustomMockMember; | ||
import com.depromeet.pool.api.PoolController; | ||
import com.depromeet.pool.service.PoolService; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.BDDMockito; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
|
||
@WebMvcTest(PoolController.class) | ||
public class PoolControllerTest extends ControllerTestConfig { | ||
@Autowired private ObjectMapper objectMapper; | ||
|
||
@MockBean PoolService poolService; | ||
|
||
@Test | ||
@WithCustomMockMember | ||
void ์ด๋ฆ์ฟผ๋ฆฌ๋ก_์์์ฅ์_์กฐํํฉ๋๋ค() throws Exception { | ||
mockMvc.perform(get("/api/pool/search").param("nameQuery", "๊ฒ์์ธ์")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.code").value("POOL_1")) | ||
.andExpect(jsonPath("$.message").value("์์์ฅ ๊ฒ์์ ์ฑ๊ณตํ์์ต๋๋ค")) | ||
.andDo(print()); | ||
} | ||
|
||
@Test | ||
@WithCustomMockMember | ||
void ์ฆ๊ฒจ์ฐพ๊ธฐ_์์์ฅ_๋ฐ_์ต๊ทผ_๊ฒ์_์์์ฅ์_์กฐํํฉ๋๋ค() throws Exception { | ||
mockMvc.perform(get("/api/pool/search/initial")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.code").value("POOL_2")) | ||
.andExpect(jsonPath("$.message").value("์ฆ๊ฒจ์ฐพ๊ธฐ ๋ฐ ์ต๊ทผ ๊ฒ์ ์์์ฅ ์กฐํ๋ฅผ ์ฑ๊ณตํ์์ต๋๋ค")) | ||
.andDo(print()); | ||
} | ||
|
||
@Test | ||
@WithCustomMockMember | ||
void ์์์ฅ์_์ฆ๊ฒจ์ฐพ๊ธฐ์_๋ฑ๋กํฉ๋๋ค() throws Exception { | ||
Map<String, Long> requestBody = new HashMap<>(); | ||
requestBody.put("poolId", 1L); | ||
BDDMockito.given(poolService.putFavoritePool(any(), any())).willReturn("1"); | ||
|
||
mockMvc.perform( | ||
put("/api/pool/favorite") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(requestBody))) | ||
.andExpect(status().isCreated()) | ||
.andDo(print()); | ||
} | ||
|
||
@Test | ||
@WithCustomMockMember | ||
void ์์์ฅ์_์ฆ๊ฒจ์ฐพ๊ธฐ์์_์ญ์ ํฉ๋๋ค() throws Exception { | ||
Map<String, Long> requestBody = new HashMap<>(); | ||
requestBody.put("poolId", 1L); | ||
BDDMockito.given(poolService.putFavoritePool(any(), any())).willReturn(null); | ||
|
||
mockMvc.perform( | ||
put("/api/pool/favorite") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(requestBody))) | ||
.andExpect(status().isNoContent()) | ||
.andDo(print()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
module-presentation/src/test/java/com/depromeet/memory/fixture/MemberFixture.java
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,16 @@ | ||
package com.depromeet.memory.fixture; | ||
|
||
import com.depromeet.member.Member; | ||
import com.depromeet.member.MemberRole; | ||
|
||
public class MemberFixture { | ||
public static Member make(Long userId, String role) { | ||
return Member.builder() | ||
.id(userId) | ||
.name("member") | ||
.email("test@gmail.com") | ||
.role(MemberRole.valueOf(role)) | ||
.goal(1000) | ||
.build(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
module-presentation/src/test/java/com/depromeet/memory/fixture/PoolFixture.java
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,9 @@ | ||
package com.depromeet.memory.fixture; | ||
|
||
import com.depromeet.pool.Pool; | ||
|
||
public class PoolFixture { | ||
public static Pool make(String name, String address, Integer lane) { | ||
return Pool.builder().name(name).address(address).lane(lane).build(); | ||
} | ||
} |
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
Oops, something went wrong.