billingsdk

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 customer
activateSubscription() — Activate a subscription
cancelSubscription() — Cancel a subscription
expireSubscription() — Expire immediately
setSubscriptionStatus() — Set status directly
incrementUsage() — Increment usage meter
emitWebhook() — Simulate webhook event

Compliance 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);