Skip to content

Commit

Permalink
[Fix] GroupControllerTest 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
NARUBROWN committed Mar 21, 2024
1 parent 02b6d65 commit ce4024e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public BoardResponseDto findBoard(Long id) {
);
}


@Transactional
public CommonResponseDto saveBoard(BoardRequestDto boardRequestDto) {
Board savedBoard = boardRepository.save(boardRequestDto.createBoard());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class IntroBoardServiceImpl implements AdditionalBoardService {
@Override
@Transactional(readOnly = true)
public List<BoardResponseDto> findBoardList(String topic) {
List<BoardResponseDto> responseDtoList= new ArrayList<>();
List<BoardResponseDto> responseDtoList = new ArrayList<>();
for (Board board : introBoardRepository.findAll()) {
responseDtoList.add(board.createResponse(request));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,34 @@ public void getGroupTest() throws Exception {
verify(groupService).getGroup(givenId);
}

// @WithMockUser
// @DisplayName("그룹 멤버 전체 조회 테스트")
// @Test
// public void findAllGroup() throws Exception {
// // given
// List<GroupResponseDto> expectedDtoList = new ArrayList<>();
// for (int i = 0; i < 10; i++) {
// expectedDtoList.add(expectedDto);
// }
// given(groupService.findAllGroup()).willReturn(expectedDtoList);
// // when
// mockMvc.perform(get("/groups/public/all-groups-members"))
// .andExpect(status().isOk())
// .andExpect(jsonPath("$..group_id").exists())
// .andExpect(jsonPath("$..member").exists())
// .andExpect(jsonPath("$..profileImage").exists())
// .andExpect(jsonPath("$..email").exists())
// .andExpect(jsonPath("$..blogLink").exists())
// .andExpect(jsonPath("$..gitRepositoryLink").exists())
// .andExpect(jsonPath("$..role").exists())
// .andExpect(jsonPath("$..part").exists())
// .andExpect(jsonPath("$..year").exists())
// .andExpect(jsonPath("$..createdDate").exists())
// .andExpect(jsonPath("$..lastModifiedDate").exists())
// .andDo(print());
// // then
// verify(groupService).findAllGroup();
// }
@WithMockUser
@DisplayName("그룹 멤버 전체 조회 테스트")
@Test
public void findAllGroup() throws Exception {
// given
List<GroupResponseDto> expectedDtoList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
expectedDtoList.add(expectedDto);
}
given(groupService.findAllGroup(14.5, "Android")).willReturn(expectedDtoList);
// when
mockMvc.perform(get("/groups/public/all-groups-members?year=14.5&part=Android"))
.andExpect(status().isOk())
.andExpect(jsonPath("$..group_id").exists())
.andExpect(jsonPath("$..member").exists())
.andExpect(jsonPath("$..profileImage").exists())
.andExpect(jsonPath("$..email").exists())
.andExpect(jsonPath("$..blogLink").exists())
.andExpect(jsonPath("$..gitRepositoryLink").exists())
.andExpect(jsonPath("$..role").exists())
.andExpect(jsonPath("$..part").exists())
.andExpect(jsonPath("$..year").exists())
.andExpect(jsonPath("$..createdDate").exists())
.andExpect(jsonPath("$..lastModifiedDate").exists())
.andDo(print());
// then
verify(groupService).findAllGroup(14.5, "Android");
}

@WithMockUser
@DisplayName("그룹 멤버 한 명 편성 테스트")
Expand Down Expand Up @@ -132,31 +132,31 @@ public void assignGroupTest() throws Exception {
verify(groupService).assignGroup(eq(givenId), eq(givenId), any(GroupRequestDto.class));
}

// @WithMockUser
// @DisplayName("그룹 멤버 한 명 수정 테스트")
// @Test
// public void updateGroupTest() throws Exception {
// // given
// given(groupService.updateGroup(any(GroupRequestDto.class), eq(givenId))).willReturn(expectedDto);
// String objectToJson = objectMapper.writeValueAsString(givenDto);
// // when
// mockMvc.perform(patch("/groups?id="+givenId).content(objectToJson).contentType(MediaType.APPLICATION_JSON).with(csrf()))
// .andExpect(status().isOk())
// .andExpect(jsonPath("$..group_id").exists())
// .andExpect(jsonPath("$.member").exists())
// .andExpect(jsonPath("$.profileImage").exists())
// .andExpect(jsonPath("$.email").exists())
// .andExpect(jsonPath("$.blogLink").exists())
// .andExpect(jsonPath("$.gitRepositoryLink").exists())
// .andExpect(jsonPath("$.role").exists())
// .andExpect(jsonPath("$.part").exists())
// .andExpect(jsonPath("$.year").exists())
// .andExpect(jsonPath("$..createdDate").exists())
// .andExpect(jsonPath("$..lastModifiedDate").exists())
// .andDo(print());
// // then
// verify(groupService).updateGroup(any(GroupRequestDto.class), eq(givenId));
// }
@WithMockUser
@DisplayName("그룹 멤버 한 명 수정 테스트")
@Test
public void updateGroupTest() throws Exception {
// given
given(groupService.updateGroup(any(GroupRequestDto.class), eq(givenId), eq(givenId))).willReturn(expectedDto);
String objectToJson = objectMapper.writeValueAsString(givenDto);
// when
mockMvc.perform(patch("/groups?groupId=1&roleId=1").content(objectToJson).contentType(MediaType.APPLICATION_JSON).with(csrf()))
.andExpect(status().isOk())
.andExpect(jsonPath("$..group_id").exists())
.andExpect(jsonPath("$.member").exists())
.andExpect(jsonPath("$.profileImage").exists())
.andExpect(jsonPath("$.email").exists())
.andExpect(jsonPath("$.blogLink").exists())
.andExpect(jsonPath("$.gitRepositoryLink").exists())
.andExpect(jsonPath("$.role").exists())
.andExpect(jsonPath("$.part").exists())
.andExpect(jsonPath("$.year").exists())
.andExpect(jsonPath("$..createdDate").exists())
.andExpect(jsonPath("$..lastModifiedDate").exists())
.andDo(print());
// then
verify(groupService).updateGroup(any(GroupRequestDto.class), eq(givenId), eq(givenId));
}

@WithMockUser
@DisplayName("그룹 멤버 한 명 삭제 테스트")
Expand Down

0 comments on commit ce4024e

Please sign in to comment.