mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-10-16 07:25:44 -04:00
test(db): cover platform seeding, session cleanup, and import recovery
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
6 files changed
+296
-1
No files matched your search
@@ -0,0 +1,85 @@
|
||||
import { beforeEach, describe, expect, test } from "vitest";
|
||||
|
||||
import { clearAllTables, insertUser, testDb } from "@sofa/test/db";
|
||||
|
||||
import { deleteExpiredSessions, deleteExpiredVerifications } from "../src/queries/auth-cleanup";
|
||||
import { session, verification } from "../src/schema";
|
||||
|
||||
const HOUR = 60 * 60 * 1000;
|
||||
|
||||
beforeEach(() => {
|
||||
clearAllTables();
|
||||
});
|
||||
|
||||
describe("deleteExpiredSessions", () => {
|
||||
test("deletes only expired sessions", () => {
|
||||
insertUser("u1");
|
||||
const now = new Date();
|
||||
testDb
|
||||
.insert(session)
|
||||
.values([
|
||||
{
|
||||
id: "s-old",
|
||||
userId: "u1",
|
||||
token: "tok-old",
|
||||
expiresAt: new Date(Date.now() - HOUR),
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
{
|
||||
id: "s-new",
|
||||
userId: "u1",
|
||||
token: "tok-new",
|
||||
expiresAt: new Date(Date.now() + HOUR),
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
])
|
||||
.run();
|
||||
|
||||
expect(deleteExpiredSessions()).toBe(1);
|
||||
expect(
|
||||
testDb
|
||||
.select()
|
||||
.from(session)
|
||||
.all()
|
||||
.map((s) => s.id),
|
||||
).toEqual(["s-new"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("deleteExpiredVerifications", () => {
|
||||
test("deletes only expired verifications", () => {
|
||||
const now = new Date();
|
||||
testDb
|
||||
.insert(verification)
|
||||
.values([
|
||||
{
|
||||
id: "v-old",
|
||||
identifier: "a@example.com",
|
||||
value: "x",
|
||||
expiresAt: new Date(Date.now() - HOUR),
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
{
|
||||
id: "v-new",
|
||||
identifier: "b@example.com",
|
||||
value: "y",
|
||||
expiresAt: new Date(Date.now() + HOUR),
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
},
|
||||
])
|
||||
.run();
|
||||
|
||||
expect(deleteExpiredVerifications()).toBe(1);
|
||||
expect(
|
||||
testDb
|
||||
.select()
|
||||
.from(verification)
|
||||
.all()
|
||||
.map((v) => v.id),
|
||||
).toEqual(["v-new"]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user