billingsdk-test
v0.1.1
Published
Testing utilities for Billing SDK
Readme
billingsdk-test
Testing utilities for Billing SDK. Includes a deterministic test adapter (zero API calls) and a shared compliance test suite.
Installation
npm install billingsdk-core billingsdk-test --save-devUsage
Test adapter
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 result = await billing.entitlements.check({
customerId: customer.id,
feature: "custom_domain",
});
expect(result.allowed).toBe(true);Test actions
| Method | Description |
|--------|-------------|
| createCustomer() | Create a test customer |
| activateSubscription() | Activate a subscription for a customer |
| cancelSubscription() | Cancel a subscription |
| expireSubscription() | Expire a subscription immediately |
| setSubscriptionStatus() | Set subscription status directly |
| incrementUsage() | Increment usage for a meter |
| emitWebhook() | Emit a simulated webhook event |
Compliance tests
import { runAdapterComplianceTests, createTestBilling } from "billingsdk-test";
import { plans } from "./plans";
const factory = () => createTestBilling({ plans });
runAdapterComplianceTests(factory);Exports
createTestBilling()— Create a billing client with the in-memory test adapterrunAdapterComplianceTests()— Run shared compliance tests against any adapter factory
