feat(api): seed dev admin + worker via admin createUser

This commit is contained in:
Bas van Rossem
2026-06-17 17:50:18 +02:00
parent dc8f550665
commit bd2d859e92
2 changed files with 40 additions and 34 deletions

View File

@@ -9,36 +9,31 @@ const SEED_NAMES = ['Leerrand', 'Frezen', 'Slijpen', 'Bekleden', 'Afwerken', 'Pr
describe('seed', () => {
it('seeds the reference activities idempotently', async () => {
await seed();
const first = await db
.select()
.from(activities)
.where(inArray(activities.name, SEED_NAMES));
const first = await db.select().from(activities).where(inArray(activities.name, SEED_NAMES));
const countFirst = first.length;
await seed();
const second = await db
.select()
.from(activities)
.where(inArray(activities.name, SEED_NAMES));
const second = await db.select().from(activities).where(inArray(activities.name, SEED_NAMES));
expect(second.length).toBe(countFirst);
expect(countFirst).toBe(SEED_NAMES.length);
const printen = await db
.select()
.from(activities)
.where(eq(activities.name, 'Printen'));
const printen = await db.select().from(activities).where(eq(activities.name, 'Printen'));
expect(printen).toHaveLength(1);
expect(printen[0]?.insoleTypes).toEqual(['3D']);
});
it('seeds the dev test account idempotently (and only once)', async () => {
it('seeds the dev worker + dev admin idempotently with correct roles', async () => {
await seed();
const first = await db.select().from(user).where(eq(user.email, 'worker@solelog.local'));
expect(first).toHaveLength(1);
const w = await db.select().from(user).where(eq(user.email, 'worker@solelog.local'));
const a = await db.select().from(user).where(eq(user.email, 'admin@solelog.local'));
expect(w).toHaveLength(1);
expect(a).toHaveLength(1);
expect((a[0] as { role?: string }).role).toBe('admin');
await seed();
const second = await db.select().from(user).where(eq(user.email, 'worker@solelog.local'));
expect(second).toHaveLength(1);
expect(await db.select().from(user).where(eq(user.email, 'admin@solelog.local'))).toHaveLength(
1
);
});
});