Add exception handler and tests for duplicate budget constraint#16
Merged
LofoWalker merged 2 commits intofeat/epic-3-budget-importfrom Feb 12, 2026
Merged
Add exception handler and tests for duplicate budget constraint#16LofoWalker merged 2 commits intofeat/epic-3-budget-importfrom
LofoWalker merged 2 commits intofeat/epic-3-budget-importfrom
Conversation
- Added BudgetAlreadyExistsException handler to GlobalExceptionMapper (returns 409) - Added unit test for duplicate budget scenario in SetCompanyBudgetUseCaseImplTest - Added integration test for duplicate budget via API in BudgetResourceTest - All tests passing successfully Co-authored-by: LofoWalker <49187988+LofoWalker@users.noreply.github.com>
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Copilot
AI
changed the title
[WIP] Update stack PR to address feedback on budget import
Add exception handler and tests for duplicate budget constraint
Feb 12, 2026
LofoWalker
approved these changes
Feb 12, 2026
There was a problem hiding this comment.
Pull request overview
Adds explicit REST-layer handling for duplicate monthly company budget creation so the API returns a semantic 409 Conflict (with a specific error code) instead of the generic domain fallback 422.
Changes:
- Added
BudgetAlreadyExistsExceptionhandling toGlobalExceptionMapper, returning HTTP 409 withBUDGET_ALREADY_EXISTS. - Added a use-case unit test asserting
BudgetAlreadyExistsExceptionis thrown and no persistence/audit occurs. - Added an integration test asserting the second budget POST in the same month is rejected with 409 and the expected error code.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/api/src/main/java/com/upkeep/infrastructure/adapter/in/rest/common/exception/GlobalExceptionMapper.java | Maps BudgetAlreadyExistsException to HTTP 409 and emits BUDGET_ALREADY_EXISTS error code. |
| apps/api/src/test/java/com/upkeep/application/usecase/SetCompanyBudgetUseCaseImplTest.java | Unit test coverage for duplicate budget detection at the use-case level. |
| apps/api/src/test/java/com/upkeep/infrastructure/adapter/in/rest/budget/BudgetResourceTest.java | Integration test coverage ensuring the API returns 409 on duplicate monthly budget creation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The API lacked proper HTTP error handling for duplicate budget attempts, falling back to generic 422 errors instead of returning semantic 409 Conflict responses.
Changes
BudgetAlreadyExistsExceptioncase toGlobalExceptionMapperreturning 409 withBUDGET_ALREADY_EXISTSerror codeshouldThrowExceptionWhenBudgetAlreadyExistsverifying domain exception is thrown when budget exists for current monthshouldRejectDuplicateBudgetForSameMonthverifying full API flow returns 409 on duplicate attemptsAPI Response
The duplicate detection logic (
findByCompanyIdAndEffectiveFromcheck) was already present from commit 848eb2d.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.