Repository navigation
feat(credits): add balance, history, and deduct API endpoints [REN-78] - #115
Merged
Merged
Conversation
…[REN-78] Three authenticated endpoints under /api/v1/credits: - GET /credits/balance — returns current credit balance - GET /credits/history — paginated ledger entry history - POST /credits/deduct — deduct credits with 402 on insufficient balance Includes 8 test cases covering happy path, pagination, insufficient credits (402), and unauthenticated access (401). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
GET /api/v1/credits/balance— authenticated balance query returning decimal stringGET /api/v1/credits/history— paginated transaction history (limit/offset, max 100)POST /api/v1/credits/deduct— usage deduction with 402 on insufficient creditsget_current_userdependencyTest plan
test_get_balance_empty— new user returns "0.0000"test_get_balance_after_allocation— reflects allocated creditstest_get_history_empty— empty list, count=0test_get_history_with_entries— correct ordering (newest first)test_get_history_pagination— limit/offset no overlaptest_deduct_credits_success— allocate 100, deduct 30, verify responsetest_deduct_insufficient— 402 with available/requestedtest_unauthenticated_returns_401— no auth → 401/403🤖 Generated with Claude Code