test(api): centralize auth helpers on server-side createUser

This commit is contained in:
Bas van Rossem
2026-06-17 17:29:46 +02:00
parent 8bfdfb736e
commit f6bd8eb036
5 changed files with 72 additions and 110 deletions

View File

@@ -5,30 +5,7 @@ import { db } from '../src/db/client';
import { workSessions } from '../src/db/schema';
import { eq } from 'drizzle-orm';
import { quote, formatDuration } from '../src/lib/csv';
const json = { 'content-type': 'application/json' };
// Sign up + sign in a user, returning the bearer token.
async function authToken(app: Hono, email: string): Promise<string> {
const password = 'sterk-wachtwoord-123';
await app.request('/api/auth/sign-up/email', {
method: 'POST',
headers: json,
body: JSON.stringify({ email, password, name: email.split('@')[0] }),
});
const signin = await app.request('/api/auth/sign-in/email', {
method: 'POST',
headers: json,
body: JSON.stringify({ email, password }),
});
const token = signin.headers.get('set-auth-token');
if (!token) throw new Error('no token');
return token;
}
function bearer(token: string): Record<string, string> {
return { authorization: `Bearer ${token}`, 'content-type': 'application/json' };
}
import { authToken, bearer } from './helpers';
async function createActivity(app: Hono, token: string, name: string): Promise<number> {
const res = await app.request('/api/activities', {