Files
zerobyte/app/test/helpers/auth.ts
Nico 61dc07b36b Controllers tests (#187)
* test: backups service

* 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

* ci: run typechecks, build and tests on PR

* test: controllers security tests

* chore: update lock file

* refactor: pr feedbacks
2025-12-19 19:25:21 +01:00

25 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 };
}