lint: fix biome issues in new test files and helpers
This commit is contained in:
1 parent
99eb3af17b
commit
93862c2275
41 files changed
+488
-314
No files matched your search
+32
-21
@@ -49,15 +49,17 @@ vi.mock("@/lib/server-log", () => ({
|
||||
vi.mock("@/lib/db", async () => {
|
||||
const schema = await import("@/db/schema");
|
||||
const { createFakeDb } = await import("@/test/fake-db");
|
||||
const fake = createFakeDb((table: unknown, projection: Record<string, unknown>) => {
|
||||
if (table === schema.UsersBadges) {
|
||||
if (state.badgeQueue.length) return state.badgeQueue.shift() as RowList;
|
||||
return state.badgeRows;
|
||||
}
|
||||
if (table === schema.User) return state.userRows;
|
||||
if (table === schema.WebsiteShopArticles) return state.articleRows;
|
||||
return [];
|
||||
});
|
||||
const fake = createFakeDb(
|
||||
(table: unknown, _projection: Record<string, unknown>) => {
|
||||
if (table === schema.UsersBadges) {
|
||||
if (state.badgeQueue.length) return state.badgeQueue.shift() as RowList;
|
||||
return state.badgeRows;
|
||||
}
|
||||
if (table === schema.User) return state.userRows;
|
||||
if (table === schema.WebsiteShopArticles) return state.articleRows;
|
||||
return [];
|
||||
},
|
||||
);
|
||||
const db = {
|
||||
...fake,
|
||||
update: (table: unknown) => ({
|
||||
@@ -116,8 +118,7 @@ describe("buyShopArticle", () => {
|
||||
state.badgeQueue = [];
|
||||
state.isBadge = false;
|
||||
state.transaction.mockImplementation(
|
||||
async (fn: (tx: unknown) => Promise<unknown>, txDb: unknown) =>
|
||||
fn(txDb),
|
||||
async (fn: (tx: unknown) => Promise<unknown>, txDb: unknown) => fn(txDb),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -127,7 +128,11 @@ describe("buyShopArticle", () => {
|
||||
);
|
||||
expect(state.rateLimit).toHaveBeenCalledWith("shop-buy:5", 5, 60_000);
|
||||
expect(state.transaction).toHaveBeenCalled();
|
||||
expect(state.update).toHaveBeenCalledWith(User, expect.anything(), expect.anything());
|
||||
expect(state.update).toHaveBeenCalledWith(
|
||||
User,
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
);
|
||||
expect(state.insert).toHaveBeenCalledTimes(2);
|
||||
expect(state.insert.mock.calls[0][0]).toBe(UsersBadges);
|
||||
expect(state.insert.mock.calls[0][1]).toEqual({
|
||||
@@ -164,9 +169,9 @@ describe("buyShopArticle", () => {
|
||||
});
|
||||
|
||||
it("omits the category query param when it is not numeric", async () => {
|
||||
await expect(buyShopArticle(shopForm({ categoryId: "abc" }))).rejects.toThrow(
|
||||
"/shop?bought=1&package=StarterPack",
|
||||
);
|
||||
await expect(
|
||||
buyShopArticle(shopForm({ categoryId: "abc" })),
|
||||
).rejects.toThrow("/shop?bought=1&package=StarterPack");
|
||||
});
|
||||
|
||||
it("raises the buyer rank when the package grants a higher rank", async () => {
|
||||
@@ -213,7 +218,10 @@ describe("buyShopArticle", () => {
|
||||
|
||||
it("ignores badge codes longer than 32 characters or whitespace", async () => {
|
||||
state.articleRows = [
|
||||
{ ...ARTICLE, badges: "OK,, , VERYLONG_badge_code_that_exceeds_32_chars" },
|
||||
{
|
||||
...ARTICLE,
|
||||
badges: "OK,, , VERYLONG_badge_code_that_exceeds_32_chars",
|
||||
},
|
||||
];
|
||||
await expect(buyShopArticle(shopForm())).rejects.toThrow(
|
||||
"/shop?category=1&bought=1",
|
||||
@@ -284,9 +292,9 @@ describe("buyShopArticle", () => {
|
||||
await expect(
|
||||
buyShopArticle(shopForm({ articleId: "t-shirt" })),
|
||||
).rejects.toThrow("/shop?category=1&error=invalid");
|
||||
await expect(buyShopArticle(shopForm({ articleId: "4.5" }))).rejects.toThrow(
|
||||
"/shop?category=1&error=invalid",
|
||||
);
|
||||
await expect(
|
||||
buyShopArticle(shopForm({ articleId: "4.5" })),
|
||||
).rejects.toThrow("/shop?category=1&error=invalid");
|
||||
expect(state.transaction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -335,7 +343,10 @@ describe("buyShopArticle", () => {
|
||||
await expect(buyShopArticle(shopForm())).rejects.toThrow(
|
||||
"/shop?category=1&bought=1",
|
||||
);
|
||||
const updateCall = state.update.mock.calls[0] as [unknown, Record<string, unknown>];
|
||||
const updateCall = state.update.mock.calls[0] as [
|
||||
unknown,
|
||||
Record<string, unknown>,
|
||||
];
|
||||
expect(updateCall[1]).toHaveProperty("credits");
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user