Skip to content

Commit 7cf0542

Browse files
fix: keep ended promotions terminal
1 parent dd0a930 commit 7cf0542

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

convex/promotions.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,22 @@ describe("promotions.setStatus", () => {
307307
expect(patches).toHaveLength(0);
308308
expect(inserts).toHaveLength(0);
309309
});
310+
311+
it("rejects reactivating an ended promotion", async () => {
312+
vi.mocked(requireUser).mockResolvedValue({
313+
userId: adminUser._id,
314+
user: adminUser,
315+
} as never);
316+
const { ctx, inserts, patches } = makeMutationCtx({
317+
existing: { ...storedPromotion, status: "ended" },
318+
});
319+
320+
await expect(
321+
setStatusHandler(ctx, { slug: validInput.slug, status: "active" }),
322+
).rejects.toThrow(/reactivated/);
323+
expect(patches).toHaveLength(0);
324+
expect(inserts).toHaveLength(0);
325+
});
310326
});
311327

312328
describe("promotions.listForStaff", () => {

convex/promotions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ async function setPromotionStatusForActor(
311311
if (existing.status === "draft" && status === "ended") {
312312
throw new ConvexError("Draft promotions must be activated before they can end");
313313
}
314+
if (existing.status === "ended" && status === "active") {
315+
throw new ConvexError("Ended promotions cannot be reactivated");
316+
}
314317
if (existing.status === status) {
315318
return { ok: true as const, slug: existing.slug, status };
316319
}

src/routes/-management/PromotionsPage.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,17 @@ describe("PromotionsPage", () => {
9898
fireEvent.click(screen.getByRole("button", { name: "Load more" }));
9999
expect(onLoadMore).toHaveBeenCalledOnce();
100100
});
101+
102+
it("does not offer to reactivate ended promotions", () => {
103+
render(
104+
<PromotionsPage
105+
promotions={[makePromotion({ status: "ended" })]}
106+
onCreate={vi.fn()}
107+
onUpdate={vi.fn()}
108+
onSetStatus={vi.fn()}
109+
/>,
110+
);
111+
112+
expect(screen.queryByRole("button", { name: "Activate" })).toBeNull();
113+
});
101114
});

src/routes/-management/PromotionsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export function PromotionsPage({
261261
>
262262
Edit
263263
</Button>
264-
{promotion.status !== "active" ? (
264+
{promotion.status === "draft" ? (
265265
<Button
266266
className="management-action-btn"
267267
type="button"

0 commit comments

Comments
 (0)