mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-04-20 23:09:16 -04:00
* 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
25 lines
644 B
TypeScript
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 };
|
|
}
|