2026-04-22 14:04:27 +02:00
|
|
|
import { describe, it, expect } from 'vitest';
|
|
|
|
|
import { openInMemoryForTest } from '../../src/lib/server/db';
|
|
|
|
|
|
|
|
|
|
describe('014_recipe_views migration', () => {
|
2026-04-22 14:08:17 +02:00
|
|
|
it('creates recipe_view table with expected columns', () => {
|
2026-04-22 14:04:27 +02:00
|
|
|
const db = openInMemoryForTest();
|
2026-04-22 14:08:17 +02:00
|
|
|
const cols = db.prepare("PRAGMA table_info(recipe_view)").all() as Array<{
|
2026-04-22 14:04:27 +02:00
|
|
|
name: string;
|
|
|
|
|
type: string;
|
|
|
|
|
notnull: number;
|
|
|
|
|
pk: number;
|
|
|
|
|
}>;
|
|
|
|
|
const byName = Object.fromEntries(cols.map((c) => [c.name, c]));
|
|
|
|
|
expect(byName.profile_id?.type).toBe('INTEGER');
|
|
|
|
|
expect(byName.profile_id?.notnull).toBe(1);
|
|
|
|
|
expect(byName.profile_id?.pk).toBe(1);
|
|
|
|
|
expect(byName.recipe_id?.type).toBe('INTEGER');
|
2026-04-22 14:08:17 +02:00
|
|
|
expect(byName.recipe_id?.notnull).toBe(1);
|
2026-04-22 14:04:27 +02:00
|
|
|
expect(byName.recipe_id?.pk).toBe(2);
|
2026-04-22 14:08:17 +02:00
|
|
|
expect(byName.last_viewed_at?.type).toBe('TIMESTAMP');
|
2026-04-22 14:04:27 +02:00
|
|
|
expect(byName.last_viewed_at?.notnull).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('has index on (profile_id, last_viewed_at DESC)', () => {
|
|
|
|
|
const db = openInMemoryForTest();
|
|
|
|
|
const idxList = db
|
2026-04-22 14:08:17 +02:00
|
|
|
.prepare("PRAGMA index_list(recipe_view)")
|
2026-04-22 14:04:27 +02:00
|
|
|
.all() as Array<{ name: string }>;
|
2026-04-22 14:08:17 +02:00
|
|
|
expect(idxList.some((i) => i.name === 'idx_recipe_view_recent')).toBe(true);
|
2026-04-22 14:04:27 +02:00
|
|
|
});
|
|
|
|
|
});
|