- Add tsconfig.test.json + typecheck:test script so test/ is type-checked; fixes real type errors it surfaced (hashedPw typing, PartialUser|ClientUser narrowing for .email). - Add HTTP-level auth-http.test.ts for the api backend covering login/session-cookie/logout/clear-sessions/bearer-apikey flows, since ApiInterface doesn't implement the session/login methods needed to run the shared session/auth suites directly. - Make the readonly-db test in shared/users.ts actually construct a readonly db instance (previously a no-op that never ran) via a new getReadonlyDb parameter, wired up for both sqlite and api backends. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import type { BackendDbInterface } from "../../../src/db/types/DbInterface.js";
|
|
import { SqliteInterface } from "../../../src/db/sqlite/SqliteInterface.js";
|
|
import { createTestDb, createReadonlyTestDb } from "../../helpers/sqlite.js";
|
|
import { runUserTests } from "../../shared/users.js";
|
|
import { runAbodeTests } from "../../shared/abodes.js";
|
|
import { runResidentTests } from "../../shared/residents.js";
|
|
import { runApikeyTests } from "../../shared/apikeys.js";
|
|
import { runSessionTests } from "../../shared/sessions.js";
|
|
import { runAuthTests } from "../../shared/auth.js";
|
|
|
|
async function createExpiredApikey(
|
|
db: BackendDbInterface,
|
|
uid: string
|
|
): Promise<`at_${string}`> {
|
|
const si = db as SqliteInterface;
|
|
const token = (`at_${"e".repeat(32)}`) as `at_${string}`;
|
|
const kid = crypto.randomUUID();
|
|
const { sql } = si._;
|
|
si._.db.run(sql`
|
|
INSERT INTO "apikeys"("uid", "kid", "token", "name", "permissions", "expires_at")
|
|
VALUES(
|
|
${{ uuid: uid }},
|
|
${{ uuid: kid }},
|
|
${{ text: token }},
|
|
${{ text: "Expired Key" }},
|
|
${{ jsonb: {} }},
|
|
${{ date: new Date(Date.now() - 10000).toISOString() }}
|
|
)
|
|
`);
|
|
return token;
|
|
}
|
|
|
|
runUserTests("sqlite", createTestDb, createReadonlyTestDb);
|
|
runAbodeTests("sqlite", createTestDb);
|
|
runResidentTests("sqlite", createTestDb);
|
|
runApikeyTests("sqlite", createTestDb);
|
|
runSessionTests("sqlite", createTestDb);
|
|
runAuthTests("sqlite", createTestDb, createExpiredApikey);
|