|
| 1 | +package clap.server.task; |
| 2 | + |
| 3 | +import clap.server.adapter.inbound.web.dto.task.FilterPendingApprovalResponse; |
| 4 | +import clap.server.adapter.inbound.web.dto.task.FilterTaskListRequest; |
| 5 | +import clap.server.adapter.inbound.web.dto.task.OrderRequest; |
| 6 | + |
| 7 | +import clap.server.application.Task.FindTaskListService; |
| 8 | +import clap.server.application.port.inbound.domain.MemberService; |
| 9 | +import clap.server.application.port.outbound.task.LoadTaskPort; |
| 10 | +import org.junit.jupiter.api.BeforeEach; |
| 11 | +import org.junit.jupiter.api.DisplayName; |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 14 | +import org.mockito.InjectMocks; |
| 15 | +import org.mockito.Mock; |
| 16 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 17 | +import org.springframework.data.domain.*; |
| 18 | + |
| 19 | +import java.time.LocalDateTime; |
| 20 | +import java.util.List; |
| 21 | + |
| 22 | +import static org.assertj.core.api.Assertions.*; |
| 23 | + |
| 24 | +import static org.mockito.Mockito.verify; |
| 25 | +import static org.mockito.Mockito.when; |
| 26 | + |
| 27 | +@ExtendWith(MockitoExtension.class) |
| 28 | +class FindTaskListServiceTest { |
| 29 | + |
| 30 | + @Mock |
| 31 | + private MemberService memberService; |
| 32 | + @Mock |
| 33 | + private LoadTaskPort loadTaskPort; |
| 34 | + @InjectMocks |
| 35 | + private FindTaskListService findTaskListService; |
| 36 | + |
| 37 | + private FilterTaskListRequest filterTaskListRequest; |
| 38 | + private Pageable pageable; |
| 39 | + private Page<FilterPendingApprovalResponse> expectedResponse; |
| 40 | + |
| 41 | + @BeforeEach |
| 42 | + void setUp() { |
| 43 | + pageable = PageRequest.of(0, 20); |
| 44 | + filterTaskListRequest = new FilterTaskListRequest( |
| 45 | + null, List.of(2L), List.of(1L), "작업 제목", "", List.of(), new OrderRequest("REQUESTED_AT", "DESC") |
| 46 | + ); |
| 47 | + |
| 48 | + FilterPendingApprovalResponse response = new FilterPendingApprovalResponse( |
| 49 | + 1L, "TC001", LocalDateTime.of(2025, 1, 24, 12, 30), |
| 50 | + "메인 카테고리", "서브 카테고리", "작업 제목", "atom.park" |
| 51 | + ); |
| 52 | + |
| 53 | + FilterPendingApprovalResponse response2 = new FilterPendingApprovalResponse( |
| 54 | + 2L, "TC002", LocalDateTime.of(2025, 1, 15, 14, 30), |
| 55 | + "메인 카테고리2", "서브 카테고리2", "다른 작업 제목", "john.doe" |
| 56 | + ); |
| 57 | + expectedResponse = new PageImpl<>(List.of(response, response2), pageable, 1); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + @DisplayName("승인대기 중인 작업요청목록 조회") |
| 62 | + void findPendingApprovalTasks_ReturnFilteredTasks() { |
| 63 | + // given |
| 64 | + Long managerId = 1L; |
| 65 | + when(loadTaskPort.findPendingApprovalTasks(pageable, filterTaskListRequest)) |
| 66 | + .thenReturn(expectedResponse); |
| 67 | + |
| 68 | + // when |
| 69 | + Page<FilterPendingApprovalResponse> result = findTaskListService.findPendingApprovalTasks(managerId, pageable, filterTaskListRequest); |
| 70 | + |
| 71 | + // then |
| 72 | + assertThat(result).isNotNull(); |
| 73 | + assertThat(result.getTotalElements()).isEqualTo(2); |
| 74 | + |
| 75 | + assertThat(result.getContent()).hasSize(2) |
| 76 | + .extracting(FilterPendingApprovalResponse::taskId) |
| 77 | + .containsExactly(1L, 2L); |
| 78 | + |
| 79 | + assertThat(result.getContent().get(0)) |
| 80 | + .extracting(FilterPendingApprovalResponse::taskId, FilterPendingApprovalResponse::taskCode, |
| 81 | + FilterPendingApprovalResponse::requestedAt, FilterPendingApprovalResponse::mainCategoryName, |
| 82 | + FilterPendingApprovalResponse::categoryName, FilterPendingApprovalResponse::title, |
| 83 | + FilterPendingApprovalResponse::requesterName) |
| 84 | + .containsExactly(1L, "TC001", LocalDateTime.of(2025, 1, 24, 12, 30), |
| 85 | + "메인 카테고리", "서브 카테고리", "작업 제목", "atom.park"); |
| 86 | + |
| 87 | + assertThat(result.getContent().get(1)) |
| 88 | + .extracting(FilterPendingApprovalResponse::taskId, FilterPendingApprovalResponse::taskCode, |
| 89 | + FilterPendingApprovalResponse::requestedAt, FilterPendingApprovalResponse::mainCategoryName, |
| 90 | + FilterPendingApprovalResponse::categoryName, FilterPendingApprovalResponse::title, |
| 91 | + FilterPendingApprovalResponse::requesterName) |
| 92 | + .containsExactly(2L, "TC002", LocalDateTime.of(2025, 1, 15, 14, 30), |
| 93 | + "메인 카테고리2", "서브 카테고리2", "다른 작업 제목", "john.doe"); |
| 94 | + |
| 95 | + verify(loadTaskPort).findPendingApprovalTasks(pageable, filterTaskListRequest); |
| 96 | + } |
| 97 | +} |
0 commit comments