db:seed now also creates a ready-made dev account via better-auth (properly hashed), idempotent, and SKIPPED when NODE_ENV=production so no known-password account ships to prod. Credentials: worker@solelog.local / werkplaats123. Documented in the worker README. API tests 37/37 green; verified live (sign-in returns a bearer token; /api/me returns the user).
45 lines
1.4 KiB
TypeScript
45 lines
1.4 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 test account idempotently (and only once)', async () => {
|
|
await seed();
|
|
const first = await db.select().from(user).where(eq(user.email, 'worker@solelog.local'));
|
|
expect(first).toHaveLength(1);
|
|
|
|
await seed();
|
|
const second = await db.select().from(user).where(eq(user.email, 'worker@solelog.local'));
|
|
expect(second).toHaveLength(1);
|
|
});
|
|
});
|