Skip to content

[fix] 주간 캘린더 예상 근무비에 SCHEDULED 근무 포함#177

Merged
geunyong16 merged 2 commits into
mainfrom
fix/156-weekly-calendar-expected-pay
May 4, 2026
Merged

[fix] 주간 캘린더 예상 근무비에 SCHEDULED 근무 포함#177
geunyong16 merged 2 commits into
mainfrom
fix/156-weekly-calendar-expected-pay

Conversation

@geunyong16
Copy link
Copy Markdown
Collaborator

@geunyong16 geunyong16 commented May 3, 2026

🔖 관련 GitHub Issue

📝 변경 사항

주요 변경 내용

  • SCHEDULED 상태의 근무 기록에도 예상 급여 계산 적용
  • 주간 캘린더 API가 완료된 근무와 예정된 근무 모두의 급여를 반환

상세 설명

문제

WorkRecordDto.DetailedResponsetotalSalary 필드가 SCHEDULED 상태 근무에서 항상 0으로 반환되어, 주간 캘린더의 '이번 주 예상 근무비' 계산 시 완료된 근무만 반영되는 버그.

원인

기존 코드는 WorkRecordCommandServiceWorkRecordGenerationService에서 COMPLETED 상태일 때만 calculationService.calculateWorkRecordDetails()를 호출하고, SCHEDULED 상태는 급여 계산을 건너뜀.

수정 내용

  • createWorkRecordByEmployer(): COMPLETED 조건 제거, SCHEDULED 생성 시에도 예상 급여 계산
  • createWorkRecordsBatch(): 전체 레코드에 예상 급여 일괄 계산 후 저장 (완료 레코드만 일괄 저장하던 버그도 함께 수정)
  • updateWorkRecord(): COMPLETED 조건 제거, SCHEDULED 수정 시에도 예상 급여 재계산
  • WorkRecordGenerationService: WorkRecordCalculationService 주입 추가, 자동 생성 레코드에도 예상 급여 계산 적용

SCHEDULED 근무가 COMPLETED로 전환되면 기존처럼 정확한 계산이 다시 수행됨.

📸 스크린샷 (선택사항)

스크린샷 보기

Before

After

✅ 체크리스트

  • PR 제목이 형식에 맞는가? (유형: 작업 요약)
  • 코드가 정상적으로 빌드되는가?
  • 새로운 기능에 대한 테스트 코드를 작성했는가?
  • 모든 테스트가 통과하는가?
  • 코드 스타일 가이드를 따랐는가?
  • 관련 문서를 업데이트했는가?

🔗 관련 PR

  • Related to #

Summary by CodeRabbit

릴리스 노트

  • 버그 수정

    • 작업 기록 생성 및 업데이트 시 세부 정보 계산이 모든 상태에서 일관성 있게 적용되도록 개선
  • 리팩토링

    • 작업 기록 관련 데이터 처리 로직 정리 및 최적화

SCHEDULED 상태의 근무 기록도 예상 급여를 계산하여 저장하도록 수정.
이전에는 COMPLETED 상태만 급여를 계산하여 주간 캘린더의 '이번 주 예상 근무비'가
완료된 근무만 반영되는 버그가 있었음.

- createWorkRecordByEmployer: SCHEDULED 생성 시에도 예상 급여 계산
- createWorkRecordsBatch: 전체 레코드 예상 급여 일괄 계산 후 저장
- updateWorkRecord: SCHEDULED 수정 시에도 예상 급여 재계산
- WorkRecordGenerationService: 자동 생성 레코드에도 예상 급여 계산 적용
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 3, 2026

Walkthrough

근무 기록 생성 및 수정 시, 계산 단계가 모든 근무 기록(SCHEDULED 포함)에 적용되도록 변경되었습니다. 일관성 검증은 COMPLETED 상태에만 유지되며, 배치 생성도 동일한 패턴으로 업데이트되었습니다.

Changes

근무 기록 계산 범위 확대

Layer / File(s) Summary
Core Logic Adjustment
src/main/java/com/example/paycheck/domain/workrecord/service/WorkRecordCommandService.java
createWorkRecordByEmployer, updateWorkRecord, createWorkRecordsBatch 메서드에서 calculateWorkRecordDetails 또는 calculateWorkRecordDetailsBatch를 모든 근무 기록에 적용하도록 변경. validateWorkRecordConsistency는 COMPLETED 상태에만 조건부 실행 유지.
Generation Service Integration
src/main/java/com/example/paycheck/domain/workrecord/service/WorkRecordGenerationService.java
WorkRecordCalculationService 의존성 추가 및 기간 근무 기록 생성 후 모든 레코드에 대해 calculateWorkRecordDetailsBatch 호출 추가.
Test Updates
src/test/java/com/example/paycheck/domain/workrecord/service/WorkRecordCommandServiceTest.java, src/test/java/com/example/paycheck/domain/workrecord/service/WorkRecordGenerationServiceTest.java
createWorkRecordByEmployer_Success_Future에서 리포지토리 save 호출 검증을 times(2)로 업데이트; WorkRecordGenerationServiceTestWorkRecordCalculationService mock 의존성 추가.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목이 명확하게 주요 변경사항을 반영하고 있으며, 형식도 [fix] 유형으로 올바르게 작성되었습니다.
Description check ✅ Passed PR 설명이 템플릿 형식을 충분히 따르고 있으며, 관련 이슈, 주요 변경 내용, 상세 설명, 체크리스트가 모두 포함되어 있습니다.
Linked Issues check ✅ Passed 코드 변경이 이슈 #156의 요구사항을 충족합니다. SCHEDULED 상태의 근무에도 예상 급여 계산이 적용되어 주간 캘린더가 완료된 근무와 예정된 근무 모두의 급여를 반환합니다.
Out of Scope Changes check ✅ Passed 모든 변경이 #156 이슈 해결을 위한 범위 내의 수정으로, SCHEDULED 근무의 급여 계산 추가와 관련 테스트 업데이트만 포함되어 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/156-weekly-calendar-expected-pay

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/test/java/com/example/paycheck/domain/workrecord/service/WorkRecordCommandServiceTest.java (1)

119-119: ⚡ Quick win

save 횟수 고정 검증은 테스트를 구현 디테일에 과도하게 결합시킵니다.

핵심 요구사항은 “미래(SCHEDULED) 생성 시 계산이 수행되는지”이므로, 저장 횟수보다 calculateWorkRecordDetails 호출과 validateWorkRecordConsistency 미호출을 검증하는 쪽이 회귀 방지에 더 유리합니다.

As per coding guidelines, src/test/**/*.java"Mock 사용이 적절한지 확인""Given-When-Then 패턴 준수 확인" 취지에 맞게 핵심 행위 검증 중심으로 테스트를 두는 것이 좋습니다.

🤖 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/WorkRecordCommandServiceTest.java`
at line 119, The test in WorkRecordCommandServiceTest currently asserts a fixed
number of saves via verify(workRecordRepository,
times(2)).save(any(WorkRecord.class)); change this to assert the behavioral
requirements instead: remove the times(2) save-count assertion and instead
verify that calculateWorkRecordDetails(...) on the service/utility used during
SCHEDULED creation is invoked (e.g.,
verify(...).calculateWorkRecordDetails(...)) and that
validateWorkRecordConsistency(...) is NOT invoked (e.g., verify(...,
never()).validateWorkRecordConsistency(...)); keep the Given-When-Then structure
and only mock/verify these core interactions rather than implementation details
like exact save call counts.
src/main/java/com/example/paycheck/domain/workrecord/service/WorkRecordCommandService.java (1)

98-103: @transactional 컨텍스트에서 이중 save/saveAll 호출을 단일 호출로 통합하세요.

세 경로(create/update/batch) 모두에서 계산 전후로 저장을 2번 수행하고 있습니다. calculateWorkRecordDetails 메서드가 엔티티를 in-place로 갱신하며, 클래스 레벨 @Transactional 선언으로 인해 JPA 영속성 컨텍스트가 변경사항을 자동 추적하므로, 트랜잭션 커밋 시점의 자동 flush로 충분합니다. 두 번째 save/saveAll 호출을 제거하면 불필요한 DB 쓰기를 줄일 수 있습니다.

각 메서드마다 save/saveAll 호출을 1회로 정리하는 리팩터링을 검토해 주세요.

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

In
`@src/main/java/com/example/paycheck/domain/workrecord/service/WorkRecordCommandService.java`
around lines 98 - 103, Methods handling create/update/batch are performing two
saves around calculationService.calculateWorkRecordDetails(...) (and optional
calculationService.validateWorkRecordConsistency(...)); because the class is
annotated with `@Transactional` and calculateWorkRecordDetails mutates the entity
in-place, remove the redundant second workRecordRepository.save(...) /
saveAll(...) call and ensure each method calls the repository exactly once
(either before calculations if initial persist is required or only once after
calculations) so that JPA's persistence context and automatic flush at commit
handle DB writes; update create/update/batch paths to rely on the single
save/saveAll and drop the extra one.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/test/java/com/example/paycheck/domain/workrecord/service/WorkRecordGenerationServiceTest.java`:
- Around line 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.

---

Nitpick comments:
In
`@src/main/java/com/example/paycheck/domain/workrecord/service/WorkRecordCommandService.java`:
- Around line 98-103: Methods handling create/update/batch are performing two
saves around calculationService.calculateWorkRecordDetails(...) (and optional
calculationService.validateWorkRecordConsistency(...)); because the class is
annotated with `@Transactional` and calculateWorkRecordDetails mutates the entity
in-place, remove the redundant second workRecordRepository.save(...) /
saveAll(...) call and ensure each method calls the repository exactly once
(either before calculations if initial persist is required or only once after
calculations) so that JPA's persistence context and automatic flush at commit
handle DB writes; update create/update/batch paths to rely on the single
save/saveAll and drop the extra one.

In
`@src/test/java/com/example/paycheck/domain/workrecord/service/WorkRecordCommandServiceTest.java`:
- Line 119: The test in WorkRecordCommandServiceTest currently asserts a fixed
number of saves via verify(workRecordRepository,
times(2)).save(any(WorkRecord.class)); change this to assert the behavioral
requirements instead: remove the times(2) save-count assertion and instead
verify that calculateWorkRecordDetails(...) on the service/utility used during
SCHEDULED creation is invoked (e.g.,
verify(...).calculateWorkRecordDetails(...)) and that
validateWorkRecordConsistency(...) is NOT invoked (e.g., verify(...,
never()).validateWorkRecordConsistency(...)); keep the Given-When-Then structure
and only mock/verify these core interactions rather than implementation details
like exact save call counts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: be837e31-fcec-4e43-8756-f9732894f1f9

📥 Commits

Reviewing files that changed from the base of the PR and between c9f3611 and c364516.

📒 Files selected for processing (4)
  • src/main/java/com/example/paycheck/domain/workrecord/service/WorkRecordCommandService.java
  • src/main/java/com/example/paycheck/domain/workrecord/service/WorkRecordGenerationService.java
  • src/test/java/com/example/paycheck/domain/workrecord/service/WorkRecordCommandServiceTest.java
  • src/test/java/com/example/paycheck/domain/workrecord/service/WorkRecordGenerationServiceTest.java

Comment on lines +35 to +37
@Mock
private WorkRecordCalculationService calculationService;

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.

@geunyong16 geunyong16 merged commit f06e6aa into main May 4, 2026
2 checks passed
@geunyong16 geunyong16 deleted the fix/156-weekly-calendar-expected-pay branch May 4, 2026 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 주간 캘린더 '이번 주 예상 근무비'가 완료된 근무만 계산함

1 participant