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
@@ -59,14 +59,16 @@ vi.mock("@/lib/services/site-settings", () => ({
|
||||
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 ("total" in projection) {
|
||||
if (state.failCount) return Promise.reject(new Error("count down"));
|
||||
return [{ total: state.countTotal }];
|
||||
}
|
||||
if (state.failUsernameCheck) throw new Error("check down");
|
||||
return state.userRows;
|
||||
});
|
||||
const fake = createFakeDb(
|
||||
(_table: unknown, projection: Record<string, unknown>) => {
|
||||
if ("total" in projection) {
|
||||
if (state.failCount) return Promise.reject(new Error("count down"));
|
||||
return [{ total: state.countTotal }];
|
||||
}
|
||||
if (state.failUsernameCheck) throw new Error("check down");
|
||||
return state.userRows;
|
||||
},
|
||||
);
|
||||
return {
|
||||
...schema,
|
||||
db: {
|
||||
@@ -163,14 +165,14 @@ describe("register", () => {
|
||||
expect(values.username).toBe("Bob_88");
|
||||
expect(values.mail).toBe("[email protected]");
|
||||
expect(state.after).toHaveBeenCalledOnce();
|
||||
await state.afterCb!();
|
||||
await state.afterCb?.();
|
||||
expect(state.sendVerification).toHaveBeenCalledWith("[email protected]");
|
||||
});
|
||||
|
||||
it("logs a warning when the verification email fails to send", async () => {
|
||||
state.sendVerification.mockRejectedValue(new Error("smtp down"));
|
||||
await register(PREV, buildForm({ mail: "[email protected]" }));
|
||||
await state.afterCb!();
|
||||
await state.afterCb?.();
|
||||
expect(state.logger.warn).toHaveBeenCalledWith(
|
||||
"Failed to send verification email after registration",
|
||||
);
|
||||
@@ -219,7 +221,10 @@ describe("register", () => {
|
||||
it("rejects passwords without a digit", async () => {
|
||||
const result = await register(
|
||||
PREV,
|
||||
buildForm({ password: "Secretsecret", password_confirmation: "Secretsecret" }),
|
||||
buildForm({
|
||||
password: "Secretsecret",
|
||||
password_confirmation: "Secretsecret",
|
||||
}),
|
||||
);
|
||||
expect(result.error).toContain("digit");
|
||||
});
|
||||
@@ -317,7 +322,10 @@ describe("register", () => {
|
||||
it("rejects an already-taken username", async () => {
|
||||
state.userRows = [{ id: 7 }];
|
||||
const result = await runValidRegistration();
|
||||
expect(result).toEqual({ error: "That username is already taken", ok: false });
|
||||
expect(result).toEqual({
|
||||
error: "That username is already taken",
|
||||
ok: false,
|
||||
});
|
||||
expect(state.insert).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -339,7 +347,10 @@ describe("register", () => {
|
||||
cause: { code: "ER_DUP_ENTRY" },
|
||||
});
|
||||
const result = await runValidRegistration();
|
||||
expect(result).toEqual({ error: "That username is already taken", ok: false });
|
||||
expect(result).toEqual({
|
||||
error: "That username is already taken",
|
||||
ok: false,
|
||||
});
|
||||
expect(state.logger.error).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -367,4 +378,4 @@ describe("register", () => {
|
||||
const values = state.insert.mock.calls[0][1] as { look: string };
|
||||
expect(values.look).toBe("hr-123-42.hd-180-1");
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user