fix: attach dashboard one off

This commit is contained in:
John Yeo
2026-02-20 23:52:46 +00:00
parent 660fb4288a
commit 635845b771
4 changed files with 50 additions and 4 deletions

View File

@@ -53,6 +53,8 @@ export const handleStripeCheckoutErrors = ({
autumnBillingPlan,
});
console.log("recurringIntervals", recurringIntervals);
// If we have more than one unique recurring interval, throw an error
if (recurringIntervals.size > 1) {
throw new RecaseError({

View File

@@ -336,3 +336,48 @@ test.concurrent(`${chalk.yellowBright("stripe-checkout: annual with allocated us
latestInvoiceProductId: proAnnual.id,
});
});
test.concurrent(`${chalk.yellowBright("setup-payment: monthly plan + one-time payment - invoices paid after trial")}`, async () => {
const premium = products.base({
id: "premium",
items: [
items.annualPrice({ price: 50 }),
items.oneOffMessages({ price: 100, billingUnits: 100, includedUsage: 0 }),
],
});
const { customerId, autumnV1 } = await initScenario({
customerId: "setup-payment-monthly-oneoff",
setup: [s.customer({}), s.products({ list: [premium] })],
actions: [],
});
// Attach product with quantity option for the one-off prepaid feature
const res = await autumnV1.billing.attach({
customer_id: customerId,
product_id: premium.id,
redirect_mode: "if_required",
options: [
{
feature_id: TestFeature.Messages,
quantity: 100,
},
],
});
await completeStripeCheckoutForm({ url: res.payment_url! });
const customer = await autumnV1.customers.get(customerId);
await expectProductActive({
customer,
productId: premium.id,
});
await expectCustomerFeatureCorrect({
customer,
featureId: TestFeature.Messages,
balance: 100,
usage: 0,
});
});

View File

@@ -1,10 +1,10 @@
import { expect, test } from "bun:test";
import { FreeTrialDuration } from "@autumn/shared";
import { completeSetupPaymentForm } from "@tests/utils/browserPool";
import { items } from "@tests/utils/fixtures/items.js";
import { products } from "@tests/utils/fixtures/products.js";
import { advanceTestClock } from "@tests/utils/stripeUtils.js";
import { initScenario, s } from "@tests/utils/testInitUtils/initScenario.js";
import { FreeTrialDuration } from "@autumn/shared";
import chalk from "chalk";
/**

View File

@@ -6,7 +6,7 @@ import {
type FreeTrialDuration,
type PlanTiming,
type ProductItem,
ProductItemInterval,
type ProductItemInterval,
type ProductV2,
UsageModel,
} from "@autumn/shared";
@@ -117,8 +117,7 @@ export function buildAttachRequestBody({
if (items !== null) {
body.items = items.map((item) => ({
...item,
interval: (item.interval ||
ProductItemInterval.Month) as ProductItemInterval,
interval: (item.interval ?? null) as ProductItemInterval | null,
}));
}