diff --git a/src/actions/draw-badge.test.ts b/src/actions/draw-badge.test.ts index 03dd712e..e04548ca 100644 --- a/src/actions/draw-badge.test.ts +++ b/src/actions/draw-badge.test.ts @@ -61,10 +61,14 @@ vi.mock("@/lib/db", async () => { const isExisting = (fields as { id?: unknown }).id !== undefined; return { from: () => ({ - where: () => - isExisting - ? { limit: () => state.txExisting } - : { limit: () => [{ maxSlot: state.txMax }] }, + where: () => { + const rows = isExisting + ? state.txExisting + : [{ maxSlot: state.txMax }]; + return Object.assign([...rows], { + limit: () => Object.assign([...rows], {}), + }); + }, }), }; } @@ -73,16 +77,16 @@ vi.mock("@/lib/db", async () => { ...schema, db: { select: (fields: unknown) => { - if ((fields as { credits?: unknown }).credits !== undefined) { - return { - from: () => ({ - where: () => ({ limit: () => state.buyers }), - }), - }; - } + const isCredits = + (fields as { credits?: unknown }).credits !== undefined; return { from: () => ({ - where: () => ({ limit: () => state.badges }), + where: () => { + const rows = isCredits ? state.buyers : state.badges; + return Object.assign([...rows], { + limit: () => Object.assign([...rows], {}), + }); + }, }), }; }, @@ -141,6 +145,7 @@ beforeEach(() => { mockRateLimit.mockResolvedValue({ ok: true }); mockGiveBadge.mockReset(); mockGiveBadge.mockResolvedValue(true); + state.price = "50"; state.badges = []; state.buyers = []; state.txExisting = []; @@ -339,12 +344,9 @@ describe("buyBadge", () => { state.buyers = [{ credits: 100 }]; state.txMax = 0; - try { - await buyBadge(form("1")); - } catch (e) { - console.log("CAUGHT ERROR:", e); - throw e; - } + await expect(buyBadge(form("1"))).rejects.toThrow( + `NEXT_REDIRECT: /draw-badge?bought=${"a".repeat(32)}`, + ); }); it("reports fail when an unexpected error is thrown inside the transaction", async () => {