Secure Sakani portal and show full album titles

This commit is contained in:
Leon Tonhäuser committed 2026-11-30 19:14:57 +01:00
1 parent c40ccf77cf
commit 69264ce165
49 files changed
+1362 -601

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import { eq } from "drizzle-orm";
import { afterAll, expect, test } from "vitest";
import { users } from "@/db/schema";
import { insertAdminCredential, seedAdmin } from "@/modules/auth/admin-bootstrap";
import { startPostgres } from "./postgres";
const testDb = await startPostgres();
afterAll(() => testDb.stop());
const input = { email: "existing@example.test", name: "Admin", password: "dummy seed password" };
const seed = (email: string) =>
seedAdmin({ ...input, email }, (credential) => insertAdminCredential(testDb.database, credential));
test("fails for an existing address without changing its role or verification", async () => {
const [{ id }] = await testDb.database.insert(users)
.values({ email: "Existing@example.test", name: "Editorial" })
.returning({ id: users.id });
await expect(seed(input.email)).rejects.toThrow("email is already registered");
const [account] = await testDb.database.select().from(users).where(eq(users.id, id));
expect(account).toMatchObject({ role: "EDITORIAL", emailVerified: false, name: "Editorial" });
});
test("rolls back the admin user when its credential insert fails", async () => {
const email = "rollback@example.test";
await testDb.pool.query("alter table account add constraint test_reject_credential check (provider_id <> 'credential')");
try {
await expect(seed(email)).rejects.toThrow();
const found = await testDb.database.select().from(users).where(eq(users.email, email));
expect(found).toEqual([]);
} finally {
await testDb.pool.query("alter table account drop constraint test_reject_credential");
}
});