Files
solelog/apps/api/test/seed.test.ts
2026-06-17 17:50:18 +02:00

40 lines
1.5 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { inArray, eq } from 'drizzle-orm';
import { seed } from '../src/db/seed';
import { db } from '../src/db/client';
import { activities, user } from '../src/db/schema';
const SEED_NAMES = ['Leerrand', 'Frezen', 'Slijpen', 'Bekleden', 'Afwerken', 'Printen'];
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 countFirst = first.length;
await seed();
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'));
expect(printen).toHaveLength(1);
expect(printen[0]?.insoleTypes).toEqual(['3D']);
});
it('seeds the dev worker + dev admin idempotently with correct roles', async () => {
await seed();
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();
expect(await db.select().from(user).where(eq(user.email, 'admin@solelog.local'))).toHaveLength(
1
);
});
});