Test Adapter
Deterministic billing for integration tests with zero API calls or credentials.
Installation
npm install billingsdk-test --save-dev
Usage
import { createTestBilling } from "billingsdk-test";
import { plans } from "./plans";
const billing = createTestBilling({ plans });
const customer = await billing.test.createCustomer({
externalId: "user_123",
});
await billing.test.activateSubscription({
customerId: customer.id,
plan: "pro",
});
const { allowed } = await billing.entitlements.check({
customerId: customer.id,
feature: "custom_domain",
});
expect(allowed).toBe(true);Test Actions
The test adapter provides helper methods via billing.test.*:
createCustomer() — Create a test customeractivateSubscription() — Activate a subscriptioncancelSubscription() — Cancel a subscriptionexpireSubscription() — Expire immediatelysetSubscriptionStatus() — Set status directlyincrementUsage() — Increment usage meteremitWebhook() — Simulate webhook eventCompliance Tests
Use the shared compliance test suite to verify any adapter conforms to the expected contract:
import { runAdapterComplianceTests, createTestBilling } from "billingsdk-test";
const factory = () => createTestBilling({ plans });
runAdapterComplianceTests(factory);