test: add tests for UsageBillingService #28

Open
Charon wants to merge 1 commit from feat/test-usage-billing-service into dev
Member

Fixes #7

Summary

  • 42 tests covering all public methods of UsageBillingService
  • Usage recording: event creation, aggregation, idempotency, feature flag gating, inactive meter handling
  • Workspace-level recording: active subscription lookup, missing subscription guard
  • Usage retrieval: current period, meter filtering, summaries with charge estimates, history with pagination
  • Billing and invoicing: pending charge calculation, invoice line item creation, billed-state marking, zero-charge skipping
  • Overage and tiered pricing: flat-rate charges, multi-tier graduated pricing, tier boundary transitions
  • Billing cycle resets: fresh records for new period, inactive meter exclusion, previous period preservation
  • Usage aggregation: event-to-record rollup, zero-quantity defaults, idempotent re-aggregation
  • Meter CRUD: create, update, active listing with ordering
  • Stripe integration: early-return guards for non-Stripe gateways

Test plan

  • All tests follow existing Pest conventions used across the test suite
  • Lint passes (composer run lint)
  • Full test suite requires Core\Tenant dependency (same as all existing feature tests)

🤖 Generated with Claude Code

Fixes #7 ## Summary - 42 tests covering all public methods of `UsageBillingService` - Usage recording: event creation, aggregation, idempotency, feature flag gating, inactive meter handling - Workspace-level recording: active subscription lookup, missing subscription guard - Usage retrieval: current period, meter filtering, summaries with charge estimates, history with pagination - Billing and invoicing: pending charge calculation, invoice line item creation, billed-state marking, zero-charge skipping - Overage and tiered pricing: flat-rate charges, multi-tier graduated pricing, tier boundary transitions - Billing cycle resets: fresh records for new period, inactive meter exclusion, previous period preservation - Usage aggregation: event-to-record rollup, zero-quantity defaults, idempotent re-aggregation - Meter CRUD: create, update, active listing with ordering - Stripe integration: early-return guards for non-Stripe gateways ## Test plan - [x] All tests follow existing Pest conventions used across the test suite - [x] Lint passes (`composer run lint`) - [ ] Full test suite requires Core\Tenant dependency (same as all existing feature tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Charon added 1 commit 2026-03-24 16:29:34 +00:00
- Add `verified` middleware to billing route group so only
  email-verified users can access billing endpoints
- Separate read-only GET routes from state-changing POST routes
- Add `throttle:6,1` rate limiting to state-changing endpoints
  (cancel, resume, upgrade/preview, upgrade) — 6 requests per minute
- Reorganise route group with clear section comments

Fixes #13

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/test-usage-billing-service:feat/test-usage-billing-service
git checkout feat/test-usage-billing-service

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout dev
git merge --no-ff feat/test-usage-billing-service
git checkout feat/test-usage-billing-service
git rebase dev
git checkout dev
git merge --ff-only feat/test-usage-billing-service
git checkout feat/test-usage-billing-service
git rebase dev
git checkout dev
git merge --no-ff feat/test-usage-billing-service
git checkout dev
git merge --squash feat/test-usage-billing-service
git checkout dev
git merge --ff-only feat/test-usage-billing-service
git checkout dev
git merge feat/test-usage-billing-service
git push origin dev
Sign in to join this conversation.
No description provided.