Skip to content

test(billing): real integration tests in CI + coverage threshold - #78

Merged
github-actions[bot] merged 3 commits into
feature/billing-paymentsfrom
billing-ci
Jul 9, 2026
Merged

test(billing): real integration tests in CI + coverage threshold#78
github-actions[bot] merged 3 commits into
feature/billing-paymentsfrom
billing-ci

Conversation

@izzywdev

Copy link
Copy Markdown
Owner

Billing integration tests + CI

Makes the DB-gated tests actually run in CI and enforces coverage.

Integration tests now RUN in CI

  • The DB-gated suites use (DATABASE_URL ? describe : describe.skip) — kept as-is (fast local unit runs), but the new CI job supplies DATABASE_URL so they execute against a live Postgres.
  • New tests/integration/event-repo.integration.test.ts: real PgEventRepository.recordIfNew dedup against Postgres (the webhook idempotency ON CONFLICT path) — runs migrations, asserts first-seen=true / duplicate=false, distinct ids independent, JSONB payload + event_type persisted.

New unit tests (raise real coverage)

  • tests/handlers/invoice-and-trial.test.ts — invoice-paid / invoice-failed / trial-ending handlers (success + no-customer no-op paths).
  • tests/routes/simple-routes.test.ts/plans, /setup-intent, /credits (validation 400, success, Stripe 502, the credit sign-flip).

CI workflow

  • .github/workflows/billing-tests.yml — ubuntu/node 20, paths-scoped to services/billing-service/**, shared/**, billing-client/**. Provisions postgres:16 + stripe/stripe-mock service containers, builds shared, then npx jest --coverage --runInBand with DATABASE_URL (un-skips integration) and STRIPE_API_BASE/STRIPE_SECRET_KEY for the mock.
  • actionlint .github/workflows/billing-tests.yml → clean (rc=0).

stripe-mock wiring (non-breaking)

  • src/stripe-client.ts: getStripe now honours STRIPE_API_BASE (host/port/protocol override) so tests can target stripe-mock. Unset in prod = no change.

Coverage threshold

  • jest.config.js: collectCoverageFrom scoped to unit-testable logic (services/handlers/routes/mappers; excludes index bootstrap, Kafka/db/stripe glue, type-only modules, Pg* repos which are integration-only). Conservative coverageThreshold (statements/lines 60, functions 55, branches 45) so the build is green; CI is the source of truth and the numbers can be ratcheted up.

NOTE: local Windows env has the os=linux npmrc pin that breaks native installs, so jest/coverage numbers are validated by this CI job rather than locally.

Base: feature/billing-payments (PR #66).

@izzywdev

Copy link
Copy Markdown
Owner Author

Superseded: billing-service shipped via #88/#92. Reopen if these specific integration tests are still wanted as net-new coverage.

@izzywdev izzywdev closed this Jun 23, 2026
@izzywdev

Copy link
Copy Markdown
Owner Author

Reopening — verification showed billing-tests.yml (the CI workflow that runs the billing integration tests) is NOT on master, so this PR has unique value. The test files themselves are on master, but the CI runner is not. Apologies for the hasty close.

@izzywdev izzywdev reopened this Jun 23, 2026
@izzywdev
izzywdev marked this pull request as ready for review July 9, 2026 11:19
@izzywdev

izzywdev commented Jul 9, 2026

Copy link
Copy Markdown
Owner Author

@claude please progress this to completion

@claude

claude Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Claude finished @izzywdev's task in 2m 11s —— View job


PR #78 — status: deliverable is complete & green ✅

  • Read repo context + reviewed all 6 changed files
  • Verified CI: Billing Service Tests workflow
  • Reviewed the new unit + integration tests
  • Investigated the two remaining red checks
  • Reported completion status

Result

This PR's own purpose — run the DB-gated billing integration tests in CI against live Postgres + stripe-mock, and enforce coverage — is working and passing:

Check Conclusion
Billing Service Tests (billing-tests.yml, this PR) success
Auto Merge PR ❌ failure
backend-tests.yml ❌ failure

The billing workflow ran, provisioned postgres:16 + stripe/stripe-mock, built shared, un-skipped the DATABASE_URL-gated integration suite (event-repo.integration.test.ts — real PgEventRepository.recordIfNew dedup / ON CONFLICT path), ran the new unit suites, and met the coverage thresholds. That is the entire value this PR was reopened for.

The two red checks are not this PR's work — and I can't fix them

Both live under .github/workflows/, which I'm not permitted to modify (GitHub App restriction), and neither is caused by the changes here:

  1. Auto Merge PR — fails at the Enable auto-merge step (gh pr merge --auto --squash). This is a repo-wide infra issue (auto-merge not enabled on the repo / branch-protection + token permissions), not a code failure. It affects every PR, not just this one.
  2. backend-tests.yml — reported failure with zero jobs, i.e. a startup/config artifact. That workflow only triggers on pull_request to main/master/develop with backend/** path changes. This PR targets feature/billing-payments and touches no backend/** files, so it has nothing to run here.

Code review — clean

The changed files are all additive (+422 / -0) and sound:

  • stripe-client.tsSTRIPE_API_BASE override is correctly no-op in prod (var unset), so it's fully backward-compatible.
  • The unit tests exercise real success + no-op/error branches (invoice-paid/failed, trial-ending, /plans, /setup-intent, /credits incl. the credit sign-flip), which is what genuinely lifts coverage.
  • The integration test is properly gated and asserts first-seen/duplicate, id-independence, and JSONB payload persistence.

To fully merge

The remaining work is outside my scope (workflow-file edits + a repo-level merge, neither of which I can perform):

  • Merge: this can be merged now — the only relevant/required-by-content check (Billing Service Tests) is green. The other two are unrelated infra reds.
  • Optionally, to stop the noise on future billing-track PRs: scope/relax the Auto Merge PR workflow (or enable auto-merge in repo settings), and confirm backend-tests.yml's startup failure — but those are workflow-file changes a maintainer needs to make.

Nothing to commit here — the branch is already complete and its CI is green.
· branch billing-ci

auto-merge.yml:
- Add missing permissions block (contents: write, pull-requests: write)
- Add continue-on-error + fallback chain so workflow succeeds when
  auto-merge is not enabled in repo settings

backend-tests.yml:
- Sync fixed version from master: extract permit-pdp into a separate
  non-matrix permit-integration job to eliminate the 0-jobs bug caused
  by secrets context in service containers combined with strategy/matrix

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
github-actions Bot merged commit 1d8233c into feature/billing-payments Jul 9, 2026
2 checks passed
@github-actions
github-actions Bot deleted the billing-ci branch July 9, 2026 12:27
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.

2 participants