diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-07-28 15:07:57 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-07-28 15:07:57 +0200 |
| commit | 04fabf115ccea31ac504b06cc51d78423b697f60 (patch) | |
| tree | 26c21f8822ccd24fce3a80b7361382c8a87d0c96 /src/lib/server/db/groceries.test.ts | |
| parent | 45cc0afb734a422ee7765dc5c60dccbcc6721367 (diff) | |
refactor: services layer, valibot validation, shared CSS utilities, aria labels, and drizzle migrate
- Extract groceries/categories/references services with db injection
- Add valibot for form validation and safe numeric id parsing
- Fix category delete FK behavior with onDelete: set null + migration
- Replace custom migrate.js with drizzle-orm/libsql/migrator
- Add shared CSS utility classes in app.css (forms, lists, buttons)
- Add aria-pressed and aria-label on interactive elements
- Remove redundant app.css imports and unused /stores import
- Add integration tests for all services using drizzle migrate helper
- Remove smoke test; add db:migrate and db:studio scripts
Diffstat (limited to 'src/lib/server/db/groceries.test.ts')
| -rw-r--r-- | src/lib/server/db/groceries.test.ts | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/src/lib/server/db/groceries.test.ts b/src/lib/server/db/groceries.test.ts index bd14040..2f8baed 100644 --- a/src/lib/server/db/groceries.test.ts +++ b/src/lib/server/db/groceries.test.ts @@ -1,27 +1,14 @@ import { describe, it, expect, beforeEach } from 'vitest'; -import { drizzle } from 'drizzle-orm/libsql'; -import { createClient } from '@libsql/client'; import { groceries, categories } from '$lib/server/db/schema'; import { eq } from 'drizzle-orm'; +import { createTestDb } from './test-helper'; describe('groceries add', () => { - const client = createClient({ url: ':memory:' }); - const db = drizzle(client, { schema: { groceries, categories } }); + let db: Awaited<ReturnType<typeof createTestDb>>['db']; beforeEach(async () => { - await db.run(`DROP TABLE IF EXISTS groceries`); - await db.run(`DROP TABLE IF EXISTS categories`); - await db.run(`CREATE TABLE categories ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL - )`); - await db.run(`CREATE TABLE groceries ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL, - checked INTEGER NOT NULL DEFAULT 0, - created_at TEXT NOT NULL, - category_id INTEGER REFERENCES categories(id) - )`); + const testDb = await createTestDb(); + db = testDb.db; }); async function addItem(name: string, categoryId?: number | null) { |
