// apps/hq/test/auth.test.ts import { describe, it, expect } from 'vitest' import { openDb } from '../src/db' import { createStaff, login, verifySession } from '../src/auth' describe('hq auth', () => { it('logs in with correct password, rejects wrong one', async () => { const db = openDb(':memory:') await createStaff(db, { email: 'admin@tecnostac.com', displayName: 'Owner', role: 'owner', password: 'let-me-in-9' }) expect(await login(db, 'admin@tecnostac.com', 'wrong')).toBeNull() const ok = await login(db, 'admin@tecnostac.com', 'let-me-in-9') expect(ok).not.toBeNull() const staff = await verifySession(db, ok!.token) expect(staff).toMatchObject({ role: 'owner' }) }) it('rejects passwords under 8 chars at creation', async () => { const db = openDb(':memory:') await expect( createStaff(db, { email: 'a@b.c', displayName: 'X', role: 'staff', password: 'short' }), ).rejects.toThrow(/8/) }) })