Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ public WorkRecordDto.Response createWorkRecordByEmployer(WorkRecordDto.CreateReq

WorkRecord savedRecord = workRecordRepository.save(workRecord);

// COMPLETED 상태면 정확한 휴일 정보와 사업장 규모를 반영하여 재계산
// 예상 급여 계산 (SCHEDULED, COMPLETED 모두 적용)
calculationService.calculateWorkRecordDetails(savedRecord);
if (status == WorkRecordStatus.COMPLETED) {
calculationService.calculateWorkRecordDetails(savedRecord);
calculationService.validateWorkRecordConsistency(savedRecord);
workRecordRepository.save(savedRecord);
}
workRecordRepository.save(savedRecord);

// 도메인 간 협력 처리
if (status == WorkRecordStatus.COMPLETED) {
Expand Down Expand Up @@ -174,12 +174,12 @@ public WorkRecordDto.Response updateWorkRecord(Long workRecordId, WorkRecordDto.

workRecordRepository.save(workRecord);

// COMPLETED 상태면 정확한 휴일 정보와 사업장 규모를 반영하여 재계산
// 예상 급여 계산 (SCHEDULED, COMPLETED 모두 적용)
calculationService.calculateWorkRecordDetails(workRecord);
if (workRecord.getStatus() == WorkRecordStatus.COMPLETED) {
calculationService.calculateWorkRecordDetails(workRecord);
calculationService.validateWorkRecordConsistency(workRecord);
workRecordRepository.save(workRecord);
}
workRecordRepository.save(workRecord);

// 도메인 간 협력 처리
coordinatorService.handleWorkRecordUpdate(workRecord, oldWeeklyAllowance, newWeeklyAllowance);
Expand Down Expand Up @@ -349,20 +349,16 @@ public WorkRecordDto.BatchCreateResponse createWorkRecordsBatch(WorkRecordDto.Ba
// 5. WorkRecord 일괄 저장 (saveAll 사용)
List<WorkRecord> savedRecords = workRecordRepository.saveAll(workRecordsToSave);

// 6. COMPLETED 상태 WorkRecord 상세 일괄 계산
// 6. 전체 WorkRecord 예상 급여 일괄 계산 (SCHEDULED, COMPLETED 모두)
calculationService.calculateWorkRecordDetailsBatch(savedRecords);

List<WorkRecord> completedRecords = savedRecords.stream()
.filter(wr -> wr.getStatus() == WorkRecordStatus.COMPLETED)
.collect(Collectors.toList());

calculationService.calculateWorkRecordDetailsBatch(completedRecords);
for (WorkRecord completedRecord : completedRecords) {
calculationService.validateWorkRecordConsistency(completedRecord);
}
completedRecords.forEach(calculationService::validateWorkRecordConsistency);

// 7. 계산된 WorkRecord 일괄 업데이트
if (!completedRecords.isEmpty()) {
workRecordRepository.saveAll(completedRecords);
}
workRecordRepository.saveAll(savedRecords);

// 8. 도메인 협력 처리 일괄 수행 (기존 handleBatchWorkRecordCreation 활용)
coordinatorService.handleBatchWorkRecordCreation(savedRecords);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class WorkRecordGenerationService {

private final WorkRecordRepository workRecordRepository;
private final ObjectMapper objectMapper;
private final WorkRecordCalculationService calculationService;

/**
* 계약 생성 시 2개월치 WorkRecord 생성
Expand Down Expand Up @@ -93,6 +94,7 @@ public void generateWorkRecordsForPeriod(WorkerContract contract, LocalDate star
}

if (!workRecords.isEmpty()) {
calculationService.calculateWorkRecordDetailsBatch(workRecords);
workRecordRepository.saveAll(workRecords);
log.info("WorkRecord 생성 완료: {} 개 생성됨 (Contract ID={})", workRecords.size(), contract.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void createWorkRecordByEmployer_Success_Future() {

// then
assertThat(result).isNotNull();
verify(workRecordRepository).save(any(WorkRecord.class));
verify(workRecordRepository, times(2)).save(any(WorkRecord.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class WorkRecordGenerationServiceTest {
@Mock
private WorkRecordRepository workRecordRepository;

@Mock
private WorkRecordCalculationService calculationService;

Comment on lines +35 to +37
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

추가한 calculationService Mock의 핵심 호출 검증이 빠져 있습니다.

현재 테스트들은 saveAll만 검증하고 있어, 생성 경로에서 calculateWorkRecordDetailsBatch(...) 호출이 빠져도 통과할 수 있습니다. 최소 1개 케이스에서 해당 호출(및 인자 리스트)을 검증해 주세요.

예시 보강 (한 테스트에 추가)
 // then
 verify(workRecordRepository).saveAll(workRecordsCaptor.capture());
+verify(calculationService).calculateWorkRecordDetailsBatch(anyList());

As per coding guidelines, src/test/**/*.java"Mock 사용이 적절한지 확인" 규칙에 따라 새로 추가된 Mock의 핵심 상호작용을 검증해야 합니다.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/com/example/paycheck/domain/workrecord/service/WorkRecordGenerationServiceTest.java`
around lines 35 - 37, Tests in WorkRecordGenerationServiceTest added a Mock for
calculationService but never verify its key interaction, so the suite would pass
even if calculateWorkRecordDetailsBatch(...) is not called; update at least one
existing test to call Mockito.verify(calculationService) to assert
calculateWorkRecordDetailsBatch(...) was invoked with the expected argument list
(or use argument matchers like eq(...) / argThat(...) to validate contents)
after the service under test runs, ensuring you reference the mock field
calculationService and the method calculateWorkRecordDetailsBatch(...) when
adding the assertion.

@Spy
private ObjectMapper objectMapper = new ObjectMapper();

Expand Down
Loading