import { beforeEach, describe, expect, test } from "bun:test";
import type Stripe from "stripe";
const {
state,
accountSql,
disabled,
adminNotices,
processStripeEvent,
event,
post,
plan,
subscription,
resetWebhookHarness,
} = await import("./webhook.test-helper");
beforeEach(() => resetWebhookHarness());
describe("release hardening", () => {
const invoice = (subscriptionId: string) => ({
customer: "cus_1",
parent: { subscription_details: { subscription: subscriptionId } },
});
const status = () =>
(
accountSql("o1")
.query("SELECT subscription_status AS s FROM billing_customers WHERE account_id = 'o1'")
.get() as {
s: string;
}
).s;
test("events from the other Stripe mode are ignored", async () => {
const live = { ...event("customer.subscription.created", subscription("active")), livemode: true };
expect(await processStripeEvent(live as Stripe.Event)).toBe("ignored");
expect(plan("o1")).toBeNull();
expect((await post(live as Stripe.Event)).status).toBe(200);
expect(plan("o1")).toBeNull();
});
test("invoice.paid recovers a past_due subscription; an older one cannot", async () => {