-
Notifications
You must be signed in to change notification settings - Fork 1
[WTH-58] 게시판 및 댓글 테스트 코드 작성 #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "WTH-58-Weeth-\uAC8C\uC2DC\uD310-\uBC0F-\uB313\uAE00-\uD14C\uC2A4\uD2B8-\uCF54\uB4DC-\uC791\uC131"
Changes from 25 commits
0a580d4
4c65525
facba80
8fc3045
e222177
bb68f68
9924556
b5cadb9
85c5431
f8a7347
a6722a0
93260ab
35c89c4
e63fb11
850be7c
ad03511
6f690e9
2224e67
c81fb5e
3e1fe9a
596883a
81df671
f0432d7
e15b3ef
561e00f
08eff0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,22 @@ | |
| import leets.weeth.domain.board.application.dto.NoticeDTO; | ||
| import leets.weeth.domain.board.application.mapper.NoticeMapper; | ||
| import leets.weeth.domain.board.domain.entity.Notice; | ||
| import leets.weeth.domain.board.domain.test.fixture.NoticeFixture; | ||
| import leets.weeth.domain.board.domain.service.NoticeUpdateService; | ||
| import leets.weeth.domain.board.test.fixture.NoticeTestFixture; | ||
| import leets.weeth.domain.board.domain.service.NoticeFindService; | ||
| import leets.weeth.domain.file.application.dto.request.FileSaveRequest; | ||
| import leets.weeth.domain.file.application.mapper.FileMapper; | ||
| import leets.weeth.domain.file.domain.entity.File; | ||
| import leets.weeth.domain.file.domain.service.FileDeleteService; | ||
| import leets.weeth.domain.file.domain.service.FileGetService; | ||
| import leets.weeth.domain.file.domain.service.FileSaveService; | ||
| import leets.weeth.domain.file.test.fixture.FileTestFixture; | ||
| import leets.weeth.domain.user.domain.entity.User; | ||
| import leets.weeth.domain.user.domain.entity.enums.Department; | ||
| import leets.weeth.domain.user.domain.entity.enums.Position; | ||
| import leets.weeth.domain.user.domain.entity.enums.Role; | ||
| import org.junit.jupiter.api.Disabled; | ||
| import leets.weeth.domain.user.test.fixture.UserTestFixture; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
|
|
@@ -29,17 +36,18 @@ | |
| @ExtendWith(MockitoExtension.class) | ||
| class NoticeUsecaseImplTest { | ||
|
|
||
| @Mock | ||
| private NoticeFindService noticeFindService; | ||
| @InjectMocks private NoticeUsecaseImpl noticeUsecase; | ||
|
|
||
| @Mock | ||
| private FileGetService fileGetService; | ||
| @Mock private NoticeFindService noticeFindService; | ||
| @Mock private NoticeUpdateService noticeUpdateService; | ||
|
|
||
| @InjectMocks | ||
| private NoticeUsecaseImpl noticeUsecase; | ||
| @Mock private FileSaveService fileSaveService; | ||
| @Mock private FileGetService fileGetService; | ||
| @Mock private FileDeleteService fileDeleteService; | ||
|
|
||
| @Mock private NoticeMapper noticeMapper; | ||
| @Mock private FileMapper fileMapper; | ||
|
|
||
| @Mock | ||
| private NoticeMapper noticeMapper; | ||
|
|
||
| @Test | ||
| void 공지사항이_최신순으로_정렬되는지() { | ||
|
|
@@ -54,7 +62,7 @@ class NoticeUsecaseImplTest { | |
|
|
||
| List<Notice> notices = new ArrayList<>(); | ||
| for(int i = 0; i<5; i++){ | ||
| Notice notice = NoticeFixture.createNotice("공지" + i, user); | ||
| Notice notice = NoticeTestFixture.createNotice("공지" + i, user); | ||
| ReflectionTestUtils.setField(notice, "id", (long) i + 1); | ||
| notices.add(notice); | ||
| } | ||
|
|
@@ -98,7 +106,6 @@ class NoticeUsecaseImplTest { | |
| assertThat(noticeResponses.hasNext()).isTrue(); | ||
|
|
||
| verify(noticeFindService, times(1)).findRecentNotices(pageable); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -114,12 +121,12 @@ class NoticeUsecaseImplTest { | |
|
|
||
| List<Notice> notices = new ArrayList<>(); | ||
| for(int i = 0; i<3; i++){ | ||
| Notice notice = NoticeFixture.createNotice("공지" + i, user); | ||
| Notice notice = NoticeTestFixture.createNotice("공지" + i, user); | ||
| ReflectionTestUtils.setField(notice, "id", (long) i + 1); | ||
| notices.add(notice); | ||
| } | ||
| for(int i = 3; i<6; i++){ | ||
| Notice notice = NoticeFixture.createNotice("검색" + i, user); | ||
| Notice notice = NoticeTestFixture.createNotice("검색" + i, user); | ||
| ReflectionTestUtils.setField(notice, "id", (long) i + 1); | ||
| notices.add(notice); | ||
| } | ||
|
|
@@ -182,13 +189,60 @@ class NoticeUsecaseImplTest { | |
| verify(noticeFindService, times(1)).search("검색", pageable); | ||
| } | ||
|
|
||
| @Disabled("TODO: update 기능 테스트 구현 필요") | ||
| @Test | ||
| void update() { | ||
| @DisplayName("공지사항 수정 시 기존 파일 삭제 후 새 파일로 업데이트된다") | ||
| void update_replacesOldFilesWithNewFiles() { | ||
| // given | ||
| Long noticeId = 1L; | ||
| Long userId = 1L; | ||
|
|
||
| User user = UserTestFixture.createActiveUser1(userId); | ||
| Notice notice = NoticeTestFixture.createNotice(noticeId, "기존 제목", user); | ||
|
|
||
| File oldFile = FileTestFixture.createFile(1L, "old.pdf", "https://example.com/old.pdf", notice); | ||
| List<File> oldFiles = List.of(oldFile); | ||
|
|
||
| NoticeDTO.Update dto = new NoticeDTO.Update("수정된 제목", "수정된 내용", | ||
| List.of(new FileSaveRequest("new.pdf", "https://example.com/new.pdf"))); | ||
|
|
||
| File newFile = FileTestFixture.createFile(2L, "new.pdf", "https://example.com/new.pdf", notice); | ||
| List<File> newFiles = List.of(newFile); | ||
|
|
||
| NoticeDTO.SaveResponse expectedResponse = new NoticeDTO.SaveResponse(noticeId); | ||
|
|
||
| given(noticeFindService.find(noticeId)).willReturn(notice); | ||
| given(fileGetService.findAllByNotice(noticeId)).willReturn(oldFiles); | ||
| given(fileMapper.toFileList(dto.files(), notice)).willReturn(newFiles); | ||
| given(noticeMapper.toSaveResponse(notice)).willReturn(expectedResponse); | ||
|
|
||
| // when | ||
| NoticeDTO.SaveResponse response = noticeUsecase.update(noticeId, dto, userId); | ||
|
|
||
| // then | ||
| assertThat(response).isEqualTo(expectedResponse); | ||
|
|
||
| verify(noticeFindService).find(noticeId); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 호출 여부까지는 전부 검증해줄 필요는 없을 것 같아욤 |
||
| verify(fileGetService).findAllByNotice(noticeId); | ||
| verify(fileDeleteService).delete(oldFiles); | ||
| verify(fileMapper).toFileList(dto.files(), notice); | ||
| verify(fileSaveService).save(newFiles); | ||
| verify(noticeUpdateService).update(notice, dto); | ||
| } | ||
|
|
||
| @Disabled("TODO: delete 기능 테스트 구현 필요") | ||
| @Test | ||
| void delete() { | ||
| @DisplayName("공지사항 엔티티 update() 호출 시 제목과 내용이 변경된다") | ||
| void update_updatesTitleAndContent() { | ||
| // given | ||
| Long userId = 1L; | ||
| User user = UserTestFixture.createActiveUser1(userId); | ||
| Notice notice = NoticeTestFixture.createNotice(1L, "기존 제목", user); | ||
| NoticeDTO.Update dto = new NoticeDTO.Update("수정된 제목", "수정된 내용", List.of()); | ||
|
|
||
| // when | ||
| notice.update(dto); | ||
|
|
||
| // then | ||
| assertThat(notice.getTitle()).isEqualTo(dto.title()); | ||
| assertThat(notice.getContent()).isEqualTo(dto.content()); | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given 단계에서 중복되는 객체설정은 (user, notice) , setUp() 메소드로 뺴놓아도 좋을 것 같아용
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 피드백 감사합니다! 하지만 이 테스트 클래스엔는 |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
유저 Fixture 가져와서 사용해주셨네요 ! 굳👍🏻