66import clap .server .application .mapper .TaskMapper ;
77import clap .server .application .port .inbound .domain .MemberService ;
88import clap .server .application .port .outbound .task .LoadTaskPort ;
9+ import clap .server .domain .model .task .Task ;
910import org .junit .jupiter .api .BeforeEach ;
1011import org .junit .jupiter .api .DisplayName ;
1112import org .junit .jupiter .api .Test ;
2223import java .util .List ;
2324
2425import static org .assertj .core .api .Assertions .assertThat ;
25- import static org .mockito .ArgumentMatchers .any ;
2626import static org .mockito .ArgumentMatchers .eq ;
27- import static org .mockito .Mockito .verify ;
2827import static org .mockito .Mockito .when ;
2928
3029@ ExtendWith (MockitoExtension .class )
@@ -40,63 +39,91 @@ class FindTaskListServiceTest {
4039 private FilterTaskListRequest filterTaskListRequest ;
4140 private Pageable pageable ;
4241 private PageResponse <FilterPendingApprovalResponse > expectedResponse ;
43- private Page <FilterPendingApprovalResponse > pageResponse ;
42+ private Page <Task > pageResponse ;
4443
4544 @ BeforeEach
4645 void setUp () {
4746 pageable = PageRequest .of (0 , 20 );
4847 filterTaskListRequest = new FilterTaskListRequest (
4948 null , List .of (2L ), List .of (1L ), "작업 제목" , "" , List .of (), "REQUESTED_AT" , "DESC"
5049 );
51-
52- FilterPendingApprovalResponse response = new FilterPendingApprovalResponse (
53- 1L , "TC001" , LocalDateTime .of (2025 , 1 , 24 , 12 , 30 ),
54- "메인 카테고리" , "서브 카테고리" , "작업 제목" , "atom.park"
55- );
56-
57- FilterPendingApprovalResponse response2 = new FilterPendingApprovalResponse (
58- 2L , "TC002" , LocalDateTime .of (2025 , 1 , 15 , 14 , 30 ),
59- "메인 카테고리2" , "서브 카테고리2" , "다른 작업 제목" , "john.doe"
60- );
61- pageResponse = new PageImpl <>(List .of (response , response2 ), pageable , 2 );
62- expectedResponse = PageResponse .from (pageResponse );
63-
50+ Task task1 = Task .builder ()
51+ .taskId (1L )
52+ .taskCode ("TC001" )
53+ .title ("작업 제목" )
54+ .dueDate (LocalDateTime .of (2025 , 1 , 24 , 12 , 30 ))
55+ .build ();
56+
57+ Task task2 = Task .builder ()
58+ .taskId (2L )
59+ .taskCode ("TC002" )
60+ .title ("다른 작업 제목" )
61+ .dueDate (LocalDateTime .of (2025 , 1 , 15 , 14 , 30 ))
62+ .build ();
63+
64+
65+ pageResponse = new PageImpl <>(List .of (task1 , task2 ), pageable , 2 );
66+ expectedResponse = PageResponse .from (pageResponse .map (TaskMapper ::toFilterPendingApprovalTasksResponse ));
6467 }
6568
6669 @ Test
67- @ DisplayName ("승인대기 중인 작업요청목록 조회" )
70+ @ DisplayName ("승인대기 중인 작업요청목록 조회 - 정상적인 데이터 반환 " )
6871 void findPendingApprovalTasks_ReturnFilteredTasks () {
6972 // given
7073 Long managerId = 1L ;
71- when (findTaskListService .findPendingApprovalTasks (eq (managerId ), eq (pageable ), eq (filterTaskListRequest )))
72- .thenReturn (expectedResponse );
74+ when (loadTaskPort .findTasksRequestedByUser (eq (managerId ), eq (pageable ), eq (filterTaskListRequest )))
75+ .thenReturn (pageResponse );
76+
7377 // when
7478 PageResponse <FilterPendingApprovalResponse > result = findTaskListService .findPendingApprovalTasks (managerId , pageable , filterTaskListRequest );
7579
7680 // then
7781 assertThat (result ).isNotNull ();
7882 assertThat (result .totalElements ()).isEqualTo (2 );
79-
8083 assertThat (result .content ()).hasSize (2 )
8184 .extracting (FilterPendingApprovalResponse ::taskId )
8285 .containsExactly (1L , 2L );
86+ }
87+
88+ @ Test
89+ @ DisplayName ("승인대기 중인 작업요청목록 조회 - 필터 조건에 맞는 작업 없음" )
90+ void findPendingApprovalTasks_NoTasksFound () {
91+ // given
92+ Long managerId = 1L ;
93+ FilterTaskListRequest filterWithNoResults = new FilterTaskListRequest (
94+ null , List .of (999L ), List .of (1000L ), "없는 작업 제목" , "" , List .of (), "REQUESTED_AT" , "DESC"
95+ );
96+ when (loadTaskPort .findTasksRequestedByUser (eq (managerId ), eq (pageable ), eq (filterWithNoResults )))
97+ .thenReturn (Page .empty ());
98+
99+ // when
100+ PageResponse <FilterPendingApprovalResponse > result = findTaskListService .findPendingApprovalTasks (managerId , pageable , filterWithNoResults );
83101
84- assertThat (result .content ().get (0 ))
85- .extracting (FilterPendingApprovalResponse ::taskId , FilterPendingApprovalResponse ::taskCode ,
86- FilterPendingApprovalResponse ::requestedAt , FilterPendingApprovalResponse ::mainCategoryName ,
87- FilterPendingApprovalResponse ::categoryName , FilterPendingApprovalResponse ::title ,
88- FilterPendingApprovalResponse ::requesterName )
89- .containsExactly (1L , "TC001" , LocalDateTime .of (2025 , 1 , 24 , 12 , 30 ),
90- "메인 카테고리" , "서브 카테고리" , "작업 제목" , "atom.park" );
91-
92- assertThat (result .content ().get (1 ))
93- .extracting (FilterPendingApprovalResponse ::taskId , FilterPendingApprovalResponse ::taskCode ,
94- FilterPendingApprovalResponse ::requestedAt , FilterPendingApprovalResponse ::mainCategoryName ,
95- FilterPendingApprovalResponse ::categoryName , FilterPendingApprovalResponse ::title ,
96- FilterPendingApprovalResponse ::requesterName )
97- .containsExactly (2L , "TC002" , LocalDateTime .of (2025 , 1 , 15 , 14 , 30 ),
98- "메인 카테고리2" , "서브 카테고리2" , "다른 작업 제목" , "john.doe" );
99-
100- verify (loadTaskPort ).findPendingApprovalTasks (pageable , filterTaskListRequest );
102+ // then
103+ assertThat (result ).isNotNull ();
104+ assertThat (result .totalElements ()).isEqualTo (0 );
105+ assertThat (result .content ()).isEmpty ();
106+ }
107+
108+ @ Test
109+ @ DisplayName ("승인대기 중인 작업요청목록 조회 - 필터 조건에 따른 정확한 결과 반환" )
110+ void findPendingApprovalTasks_FilterByTitle () {
111+ // given
112+ Long managerId = 1L ;
113+ FilterTaskListRequest filterByTitle = new FilterTaskListRequest (
114+ null , List .of (2L ), List .of (1L ), "작업 제목" , "" , List .of (), "REQUESTED_AT" , "DESC"
115+ );
116+ when (loadTaskPort .findTasksRequestedByUser (eq (managerId ), eq (pageable ), eq (filterByTitle )))
117+ .thenReturn (pageResponse );
118+
119+ // when
120+ PageResponse <FilterPendingApprovalResponse > result = findTaskListService .findPendingApprovalTasks (managerId , pageable , filterByTitle );
121+
122+ // then
123+ assertThat (result ).isNotNull ();
124+ assertThat (result .totalElements ()).isEqualTo (2 );
125+ assertThat (result .content ())
126+ .extracting (FilterPendingApprovalResponse ::title )
127+ .containsExactly ("작업 제목" , "다른 작업 제목" );
101128 }
102129}
0 commit comments