Skip to content

feat(credits): add balance, history, and deduct API endpoints [REN-78] - #115

Merged
Scott Graham (cheddarfox) merged 1 commit into
devfrom
REN-78-credit-api-endpoints
Mar 9, 2026
Merged

Scott Graham (cheddarfox) merged 1 commit into
devfrom
REN-78-credit-api-endpoints

Conversation

@cheddarfox

Copy link
Copy Markdown
Member

Summary

  • GET /api/v1/credits/balance — authenticated balance query returning decimal string
  • GET /api/v1/credits/history — paginated transaction history (limit/offset, max 100)
  • POST /api/v1/credits/deduct — usage deduction with 402 on insufficient credits
  • All endpoints require Bearer auth via get_current_user dependency
  • 8 integration tests with blacklist mock fixture

Test plan

  • test_get_balance_empty — new user returns "0.0000"
  • test_get_balance_after_allocation — reflects allocated credits
  • test_get_history_empty — empty list, count=0
  • test_get_history_with_entries — correct ordering (newest first)
  • test_get_history_pagination — limit/offset no overlap
  • test_deduct_credits_success — allocate 100, deduct 30, verify response
  • test_deduct_insufficient — 402 with available/requested
  • test_unauthenticated_returns_401 — no auth → 401/403

🤖 Generated with Claude Code

…[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>
@cheddarfox
Scott Graham (cheddarfox) merged commit 2d56f28 into dev Mar 9, 2026
11 of 13 checks passed
@cheddarfox
Scott Graham (cheddarfox) deleted the REN-78-credit-api-endpoints branch March 9, 2026 23:11
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.

1 participant