fix: resolve draw-badge test mock iterability issues and failing edge cases
- Update txSelect and db.select mocks in draw-badge.test.ts to return iterable array-like objects with limit methods - Reset state.price in beforeEach - Fix test assertions for unsafe character stripping test - All 3,066 tests now pass cleanly
This commit is contained in:
1 parent
b13b3a50ff
commit
aec5771397
1 file changed
+20
-18
@@ -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 () => {
|
||||
|
||||
Reference in new issue
Block a user