-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐งช [Test] Admin ์นดํ
๊ณ ๋ฆฌ ์ถ๊ฐ ๋ฐ ์ ๊ฑฐ ํ
์คํธ ์ฝ๋ ์์ฑ (#760)
- Loading branch information
Showing
7 changed files
with
190 additions
and
14 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
11 changes: 10 additions & 1 deletion
11
.../src/main/java/gg/party/api/admin/category/controller/request/CategoryAddAdminReqDto.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 |
---|---|---|
@@ -1,10 +1,19 @@ | ||
package gg.party.api.admin.category.controller.request; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.Size; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED) | ||
public class CategoryAddAdminReqDto { | ||
@NotBlank(message = "์นดํ ๊ณ ๋ฆฌ ์ด๋ฆ์ ๋น์ด ์์ ์ ์์ต๋๋ค.") | ||
@Size(min = 1, max = 10, message = "์นดํ ๊ณ ๋ฆฌ ์ด๋ฆ์ 1์ ์ด์ 10์ ์ดํ์ด์ด์ผ ํฉ๋๋ค.") | ||
private String categoryName; | ||
|
||
public CategoryAddAdminReqDto(String category) { | ||
this.categoryName = category; | ||
} | ||
} |
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
163 changes: 163 additions & 0 deletions
163
gg-pingpong-api/src/test/java/gg/party/api/admin/category/CategoryAdminControllerTest.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,163 @@ | ||
package gg.party.api.admin.category; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import org.apache.http.HttpHeaders; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import gg.auth.utils.AuthTokenProvider; | ||
import gg.data.party.Category; | ||
import gg.data.party.Room; | ||
import gg.data.party.type.RoomType; | ||
import gg.data.user.User; | ||
import gg.data.user.type.RacketType; | ||
import gg.data.user.type.RoleType; | ||
import gg.data.user.type.SnsType; | ||
import gg.party.api.admin.category.controller.request.CategoryAddAdminReqDto; | ||
import gg.repo.party.CategoryRepository; | ||
import gg.repo.party.RoomRepository; | ||
import gg.utils.TestDataUtils; | ||
import gg.utils.annotation.IntegrationTest; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@IntegrationTest | ||
@AutoConfigureMockMvc | ||
@Transactional | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class CategoryAdminControllerTest { | ||
@Autowired | ||
MockMvc mockMvc; | ||
@Autowired | ||
TestDataUtils testDataUtils; | ||
@Autowired | ||
ObjectMapper objectMapper; | ||
@Autowired | ||
AuthTokenProvider tokenProvider; | ||
@Autowired | ||
RoomRepository roomRepository; | ||
@Autowired | ||
CategoryRepository categoryRepository; | ||
User userTester; | ||
String userAccessToken; | ||
Category defaultCategory; | ||
Category testCategory; | ||
Room testRoom; | ||
|
||
@Nested | ||
@DisplayName("์นดํ ๊ณ ๋ฆฌ ์ถ๊ฐ ํ ์คํธ") | ||
class CategoryAdd { | ||
@BeforeEach | ||
void beforeEach() { | ||
userTester = testDataUtils.createNewUser("adminTester", "adminTester", | ||
RacketType.DUAL, SnsType.SLACK, RoleType.ADMIN); | ||
userAccessToken = tokenProvider.createToken(userTester.getId()); | ||
defaultCategory = testDataUtils.createNewCategory("etc"); | ||
} | ||
|
||
@Test | ||
@DisplayName("์นดํ ๊ณ ๋ฆฌ ์ถ๊ฐ ์ฑ๊ณต 201") | ||
public void success() throws Exception { | ||
//given | ||
String url = "/party/admin/categories"; | ||
CategoryAddAdminReqDto categoryAddAdminReqDto = new CategoryAddAdminReqDto("category"); | ||
String jsonRequest = objectMapper.writeValueAsString(categoryAddAdminReqDto); | ||
//when | ||
String contentAsString = mockMvc.perform(post(url) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(jsonRequest) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + userAccessToken)) | ||
.andExpect(status().isCreated()) | ||
.andReturn().getResponse().getContentAsString(); | ||
//then | ||
assertThat(categoryRepository.findAll()).size().isEqualTo(2); | ||
} | ||
|
||
@Test | ||
@DisplayName("์ด๋ฏธ ์กด์ฌํ๋ ์นดํ ๊ณ ๋ฆฌ๋ก ์ธํ ์๋ฌ 409") | ||
public void fail() throws Exception { | ||
//given | ||
String url = "/party/admin/categories"; | ||
testDataUtils.createNewCategory("category"); | ||
CategoryAddAdminReqDto categoryAddAdminReqDto = new CategoryAddAdminReqDto("category"); | ||
String jsonRequest = objectMapper.writeValueAsString(categoryAddAdminReqDto); | ||
//when & then | ||
String contentAsString = mockMvc.perform(post(url) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(jsonRequest) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + userAccessToken)) | ||
.andExpect(status().isConflict()).toString(); | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("์นดํ ๊ณ ๋ฆฌ ์ญ์ ํ ์คํธ") | ||
class CategoryRemove { | ||
@BeforeEach | ||
void beforeEach() { | ||
userTester = testDataUtils.createNewUser("adminTester", "adminTester", | ||
RacketType.DUAL, SnsType.SLACK, RoleType.ADMIN); | ||
userAccessToken = tokenProvider.createToken(userTester.getId()); | ||
testCategory = testDataUtils.createNewCategory("test"); | ||
testRoom = testDataUtils.createNewRoom(userTester, userTester, testCategory, 1, 1, | ||
3, 2, 180, RoomType.OPEN); | ||
defaultCategory = testDataUtils.createNewCategory("etc"); | ||
} | ||
|
||
@Test | ||
@DisplayName("์นดํ ๊ณ ๋ฆฌ ์ญ์ ์ฑ๊ณต 204") | ||
public void success() throws Exception { | ||
//given | ||
String categoryID = testCategory.getId().toString(); | ||
String url = "/party/admin/categories/" + categoryID; | ||
//when | ||
String contentAsString = mockMvc.perform(delete(url) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + userAccessToken)) | ||
.andExpect(status().isNoContent()) | ||
.andReturn().getResponse().getContentAsString(); | ||
//then | ||
assertThat(categoryRepository.findAll()).size().isEqualTo(1); | ||
assertThat(roomRepository.findById(testRoom.getId()).get().getCategory().getName()).isEqualTo("etc"); | ||
} | ||
|
||
@Test | ||
@DisplayName("์กด์ฌํ์ง ์๋ ์นดํ ๊ณ ๋ฆฌ๋ก ์ธํ ์๋ฌ 404") | ||
public void noCategoryFail() throws Exception { | ||
//given | ||
String categoryID = "10"; | ||
String url = "/party/admin/categories/" + categoryID; | ||
//when & then | ||
String contentAsString = mockMvc.perform(delete(url) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + userAccessToken)) | ||
.andExpect(status().isNotFound()).toString(); | ||
} | ||
|
||
@Test | ||
@DisplayName("default ์นดํ ๊ณ ๋ฆฌ ์ญ์ ์์ฒญ์ ๋ํ ์๋ฌ 400") | ||
public void fail() throws Exception { | ||
//given | ||
String categoryID = defaultCategory.getId().toString(); | ||
String url = "/party/admin/categories/" + categoryID; | ||
//when & then | ||
String contentAsString = mockMvc.perform(delete(url) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + userAccessToken)) | ||
.andExpect(status().isBadRequest()).toString(); | ||
} | ||
} | ||
} |
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
6 changes: 3 additions & 3 deletions
6
gg-utils/src/main/java/gg/utils/exception/party/DefaultCategoryNeedException.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