zerobyte/app/test/helpers/auth.ts
Nicolas Meienberger 620d1bf4fd refactor: create hono app in a separate file
To avoid side effects like db migration or startup scripts when testing

test(backups): add security tests to the backups controller
2025-12-19 18:32:06 +01:00

24 lines
644 B
TypeScript

import { authService } from "~/server/modules/auth/auth.service";
import { db } from "~/server/db/db";
import { usersTable, sessionsTable } from "~/server/db/schema";
export async function createTestSession() {
const [existingUser] = await db.select().from(usersTable);
if (!existingUser) {
await authService.register("testadmin", "testpassword");
}
const [user] = await db.select().from(usersTable);
const sessionId = crypto.randomUUID();
const expiresAt = Date.now() + 1000 * 60 * 60 * 24; // 24 hours
await db.insert(sessionsTable).values({
id: sessionId,
userId: user.id,
expiresAt,
});
return { sessionId, user };
}