Restructure route organization
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { isHttpError } from '@sveltejs/kit';
|
||||
import { mockProclamation } from '$lib/test-utils';
|
||||
|
||||
vi.mock('$lib/db', () => ({
|
||||
prisma: {
|
||||
proclamation: { findUnique: vi.fn() }
|
||||
}
|
||||
}));
|
||||
|
||||
import { prisma } from '$lib/db';
|
||||
import { load } from './+page.server';
|
||||
|
||||
const findUnique = prisma.proclamation.findUnique as ReturnType<typeof vi.fn>;
|
||||
|
||||
describe('(protected)/admin/proclamations/[id] page server load', () => {
|
||||
beforeEach(() => {
|
||||
findUnique.mockReset();
|
||||
});
|
||||
|
||||
it('throws 404 when proclamation is not found', async () => {
|
||||
findUnique.mockResolvedValue(null);
|
||||
|
||||
const err = await Promise.resolve(
|
||||
load({ params: { id: 'nonexistent' } } as any)
|
||||
).catch((e: unknown) => e);
|
||||
expect(isHttpError(err, 404)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns proclamation when found', async () => {
|
||||
const proclamation = mockProclamation();
|
||||
findUnique.mockResolvedValue(proclamation);
|
||||
|
||||
const result = (await load({ params: { id: 'proc-1' } } as any)) as any;
|
||||
expect(result.proclamation).toEqual(proclamation);
|
||||
});
|
||||
|
||||
it('queries by params.id with frequency and category (including parent)', async () => {
|
||||
findUnique.mockResolvedValue(mockProclamation());
|
||||
|
||||
await load({ params: { id: 'proc-1' } } as any);
|
||||
|
||||
expect(findUnique).toHaveBeenCalledWith({
|
||||
where: { id: 'proc-1' },
|
||||
include: {
|
||||
solfeggioFrequency: true,
|
||||
category: { include: { parent: true } }
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('returns proclamation with parent category when present', async () => {
|
||||
const proclamation = mockProclamation({
|
||||
category: {
|
||||
id: 2,
|
||||
name: 'Inner Healing',
|
||||
parentId: 1,
|
||||
parent: { id: 1, name: 'Healing', parentId: null }
|
||||
}
|
||||
});
|
||||
findUnique.mockResolvedValue(proclamation);
|
||||
|
||||
const result = (await load({ params: { id: 'proc-1' } } as any)) as any;
|
||||
expect(result.proclamation.category.parent.name).toBe('Healing');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user