write-test
Write integration tests for the Autumn billing system. Use when creating tests, writing test scenarios for billing/subscription features, track/check endpoints, or when the user asks about testing, test cases, or QA.
Install
mkdir -p .claude/skills/write-test && curl -L -o skill.zip "https://mcp.directory/api/skills/download/3341" && unzip -o skill.zip -d .claude/skills/write-test && rm skill.zipInstalls to .claude/skills/write-test
About this skill
Test Writing Guide
Before Writing ANY Test
- Search for duplicate scenarios — grep the test directory for similar setups
- Read the rules file
.claude/rules/write-tests.mdc— the 20 rules agents ALWAYS get wrong
Minimal Template
import { expect, test } from "bun:test";
import { type ApiCustomerV3 } from "@autumn/shared";
import { expectCustomerFeatureCorrect } from "@tests/integration/billing/utils/expectCustomerFeatureCorrect";
import { expectStripeSubscriptionCorrect } from "@tests/integration/billing/utils/expectStripeSubCorrect";
import { TestFeature } from "@tests/setup/v2Features.js";
import { items } from "@tests/utils/fixtures/items.js";
import { products } from "@tests/utils/fixtures/products.js";
import { initScenario, s } from "@tests/utils/testInitUtils/initScenario.js";
import chalk from "chalk";
test.concurrent(`${chalk.yellowBright("feature: description")}`, async () => {
const messagesItem = items.monthlyMessages({ includedUsage: 100 });
const pro = products.pro({ items: [messagesItem] });
const { customerId, autumnV1, ctx } = await initScenario({
customerId: "unique-test-id",
setup: [s.customer({ paymentMethod: "success" }), s.products({ list: [pro] })],
actions: [s.billing.attach({ productId: pro.id })],
});
const customer = await autumnV1.customers.get<ApiCustomerV3>(customerId);
expectCustomerFeatureCorrect({ customer, featureId: TestFeature.Messages, balance: 100 });
await expectStripeSubscriptionCorrect({ ctx, customerId });
});
initScenario — The Core System
initScenario creates customers, products, entities, and runs actions sequentially. It returns everything you need.
Returned Values
const {
customerId, // Customer ID (auto-prefixed products)
autumnV1, // V1.2 API client
autumnV2, // V2.0 API client
ctx, // { db, stripeCli, org, env, features }
testClockId, // Stripe test clock ID
customer, // Customer object after creation
entities, // [{ id: "ent-1", name: "Entity 1", featureId }]
advancedTo, // Current test clock timestamp (ms)
otherCustomers, // Map<string, OtherCustomerResult>
} = await initScenario({ ... });
Setup Functions
| Function | Purpose | Notes |
|---|---|---|
s.customer({ paymentMethod?, testClock?, data?, withDefault?, skipWebhooks? }) | Configure customer | testClock defaults true. Use paymentMethod: "success" for any paid product |
s.products({ list, customerIdsToDelete? }) | Products to create | Auto-prefixed with customerId |
s.entities({ count, featureId }) | Generate entities | Creates "ent-1" through "ent-N" |
s.otherCustomers([{ id, paymentMethod? }]) | Additional customers | Share same test clock as primary |
s.deleteCustomer({ customerId } | { email }) | Pre-test cleanup | Delete before creating |
s.reward({ reward, productId }) | Standalone reward | ID auto-suffixed |
s.referralProgram({ reward, program }) | Referral program | IDs auto-suffixed |
Action Functions — WITH TIMEOUT BEHAVIOR
CRITICAL: Know which actions have built-in timeouts and which don't.
| Function | Built-in Timeout | Notes |
|---|---|---|
s.billing.attach({ productId, options?, planSchedule?, items?, newBillingSubscription? }) | 5-8s | V2 endpoint. Use for new billing tests |
s.attach({ productId, entityIndex?, options?, newBillingSubscription? }) | 4-5s | V1 endpoint. Use for legacy/update-subscription setup |
s.billing.multiAttach({ plans, entityIndex?, freeTrial? }) | 2-5s | plans: [{ productId, featureQuantities? }] |
s.cancel({ productId, entityIndex? }) | None | No timeout |
s.track({ featureId, value, entityIndex?, timeout? }) | None | Must pass timeout explicitly if needed |
s.advanceTestClock({ days?, weeks?, hours?, months? }) | Waits for Stripe | Cumulative from advancedTo |
s.advanceToNextInvoice({ withPause? }) | 30s | Advances 1 month + 96h for invoice finalization |
s.updateSubscription({ productId, entityIndex?, cancelAction?, items? }) | None | cancel_end_of_cycle, cancel_immediately, uncancel |
s.attachPaymentMethod({ type }) | None | "success", "fail", "authenticate" |
s.removePaymentMethod() | None | Remove all PMs |
s.resetFeature({ featureId, productId?, timeout? }) | 2s default | For FREE products only. Use s.advanceToNextInvoice for paid |
s.referral.createCode() | None | Create referral code |
s.referral.redeem({ customerId }) | None | Redeem for another customer |
s.billing.attach vs s.attach — They Are DIFFERENT
s.attach | s.billing.attach | |
|---|---|---|
| Endpoint | V1 /attach | V2 /billing.attach |
| Extra params | none | planSchedule, items (custom plan) |
| Prepaid quantity | Exclusive of includedUsage | Inclusive of includedUsage |
| Use when | Legacy tests, update-subscription setup | New billing/attach tests |
Product ID Prefixing
initScenario mutates product objects in-place: product.id becomes "${product.id}_${customerId}". So pro.id after initScenario already includes the prefix. Use product.id everywhere — in s.attach(), in direct API calls, and in assertions.
Multiple Customers — NEVER Call initScenario Twice
// Use s.otherCustomers in setup
const { autumnV1, otherCustomers } = await initScenario({
customerId: "cus-a",
setup: [
s.customer({ paymentMethod: "success" }),
s.products({ list: [pro] }),
s.otherCustomers([{ id: "cus-b", paymentMethod: "success" }]),
],
actions: [s.billing.attach({ productId: pro.id })],
});
// Or create manually after initScenario
await autumnV1.customers.create("cus-b", { name: "B" });
await autumnV1.billing.attach({ customer_id: "cus-b", product_id: pro.id });
Assertion Utilities — ALWAYS Use These
Product State
import { expectCustomerProducts, expectProductActive, expectProductCanceling,
expectProductScheduled, expectProductNotPresent } from "@tests/integration/billing/utils/expectCustomerProductCorrect";
// PREFERRED — batch check multiple products in one call
await expectCustomerProducts({
customer,
active: [pro.id],
canceling: [premium.id], // "canceling" = status:active + canceled_at set
scheduled: [free.id],
notPresent: [oldProduct.id],
});
// Single product checks
await expectProductActive({ customer, productId: pro.id });
await expectProductCanceling({ customer, productId: premium.id });
await expectProductScheduled({ customer, productId: free.id });
await expectProductNotPresent({ customer, productId: pro.id });
Features
import { expectCustomerFeatureCorrect } from "@tests/integration/billing/utils/expectCustomerFeatureCorrect";
// IMPORTANT: requires `customer` object, does NOT fetch from API
expectCustomerFeatureCorrect({
customer, // MUST be fetched customer object, not customerId
featureId: TestFeature.Messages,
includedUsage: 100, // optional
balance: 100, // optional
usage: 0, // optional
resetsAt: advancedTo + ms.days(30), // optional, 10min tolerance
});
Invoices
import { expectCustomerInvoiceCorrect } from "@tests/integration/billing/utils/expectCustomerInvoiceCorrect";
expectCustomerInvoiceCorrect({
customer, // ApiCustomerV3
count: 2, // Total invoice count
latestTotal: 30, // Most recent invoice total ($), +-0.01 tolerance
latestStatus: "paid",
});
Stripe Subscription (ALWAYS call after billing actions)
import { expectStripeSubscriptionCorrect } from "@tests/integration/billing/utils/expectStripeSubCorrect";
// Basic — verify all subscriptions match expected state
await expectStripeSubscriptionCorrect({ ctx, customerId });
// With options
await expectStripeSubscriptionCorrect({
ctx, customerId,
options: { subCount: 1, status: "trialing", debug: true },
});
For free products, use expectNoStripeSubscription instead:
import { expectNoStripeSubscription } from "@tests/integration/billing/utils/expectNoStripeSubscription";
await expectNoStripeSubscription({ db: ctx.db, customerId, org: ctx.org, env: ctx.env });
Trials
import { expectProductTrialing, expectProductNotTrialing } from "@tests/integration/billing/utils/expectCustomerProductTrialing";
const trialEndsAt = await expectProductTrialing({
customer, productId: pro.id, trialEndsAt: advancedTo + ms.days(7),
});
await expectProductNotTrialing({ customer, productId: pro.id });
Preview Next Cycle
import { expectPreviewNextCycleCorrect } from "@tests/integration/billing/utils/expectPreviewNextCycleCorrect";
expectPreviewNextCycleCorrect({ preview, startsAt: addMonths(advancedTo, 1).getTime(), total: 20 });
// Or when next_cycle should NOT exist:
expectPreviewNextCycleCorrect({ preview, expectDefined: false });
Proration
import { calculateProratedDiff } from "@tests/integration/billing/utils/proration";
const expected = await calculateProratedDiff({
customerId, advancedTo, oldAmount: 20, newAmount: 50,
});
expect(preview.total).toBeCloseTo(expected, 0);
Invoice Line Items (for tests verifying stored line items)
import { expectInvoiceLineItemsCorrect, expectBasePriceLineItem } from "@tests/integration/billing/utils/expectInvoiceLineItemsCorrect";
// Full check with per-item expectations
await expectInvoiceLineItemsCorrect({
stripeInvoiceId: invoice.stripe_id,
expectedTotal: 20,
expectedCount: 2,
expectedLineItems: [
{ isBasePrice: true, amount: 20, direction: "charge" },
{ featureId: TestFeature.Messages, totalAmount: 0 },
],
});
// Quick base price check
await expectBasePriceLineItem({ stripeInvoiceId,
---
*Content truncated.*
More by useautumn
View all skills by useautumn →You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
fastapi-templates
wshobson
Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.
Related MCP Servers
Browse all serversUnlock powerful Excel automation: read/write Excel files, create sheets, and automate workflows with seamless integratio
Streamline billing with Paddle API tools. Manage products, prices, and subscriptions efficiently—an alternative to Strip
AgentKit (Chargebee): seamless integration with Chargebee APIs to automate subscription billing, invoicing, and revenue
Simplify email marketing and automation with Migadu's API integration for bulk mailbox, alias, and autoresponder managem
Connect Obsidian vaults for natural language queries and secure note updates with seamless Obsidian integration.
Learn how to use Python to read a file and manipulate local files safely through the Filesystem API.
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.