Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(billing): surface failed cancellation restore to the user

Richie McIlroy35bd52da3a8c
diff --git a/apps/web/__tests__/unit/update-seat-quantity.test.ts b/apps/web/__tests__/unit/update-seat-quantity.test.ts
index a2a84fa0a..778244ff0 100644
--- a/apps/web/__tests__/unit/update-seat-quantity.test.ts
+++ b/apps/web/__tests__/unit/update-seat-quantity.test.ts
@@ -290,4 +290,26 @@ describe("updateSeatQuantity", () => {
cancel_at_period_end: true,
});
});
+
+ it("does not claim cancellation remains when restore fails", async () => {
+ mockSeatLookup({ currentQuantity: 1 });
+ mockStripe.subscriptions.retrieve.mockResolvedValue({
+ id: "sub_1",
+ cancel_at_period_end: true,
+ items: {
+ data: [{ id: "si_1", quantity: 1 }],
+ },
+ });
+ mockStripe.subscriptions.update
+ .mockResolvedValueOnce({ id: "sub_1", pending_update: null })
+ .mockRejectedValueOnce(new Error("card declined"))
+ .mockRejectedValueOnce(new Error("restore failed"));
+ const { updateSeatQuantity } = await import(
+ "@/actions/organization/update-seat-quantity"
+ );
+
+ await expect(updateSeatQuantity("org-1" as never, 2)).rejects.toThrow(
+ "keep your scheduled cancellation",
+ );
+ });
});
diff --git a/apps/web/actions/organization/update-seat-quantity.ts b/apps/web/actions/organization/update-seat-quantity.ts
index af1b19089..a2a0a6cd7 100644
--- a/apps/web/actions/organization/update-seat-quantity.ts
+++ b/apps/web/actions/organization/update-seat-quantity.ts
@@ -208,6 +208,9 @@ export async function updateSeatQuantity(
subscription.id,
restoreError,
);
+ throw new Error(
+ "We couldn't complete the seat change or keep your scheduled cancellation. Please contact support.",
+ );
}
};