- Move api.server.ts, errors.ts, types.ts, utils.ts, relativeTime.ts to lib/shared/ - Move person relationship components to lib/person/relationship/ - Move Stammbaum components to lib/person/genealogy/ - Move HelpPopover to lib/shared/primitives/ - Update all import paths across routes, specs, and lib files - Update vi.mock() paths in server-project test files - Remove now-empty legacy directories (components/, hooks/, server/, etc.) - Update vite.config.ts coverage include paths for new structure - Update frontend/CLAUDE.md to reflect domain-based lib/ layout Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
import { load } from './+layout.server';
|
|
|
|
vi.mock('$lib/shared/api.server', () => ({ createApiClient: vi.fn() }));
|
|
|
|
import { createApiClient } from '$lib/shared/api.server';
|
|
|
|
function mockApi(users: unknown[]) {
|
|
vi.mocked(createApiClient).mockReturnValue({
|
|
GET: vi.fn().mockResolvedValueOnce({ response: { ok: true }, data: users })
|
|
} as ReturnType<typeof createApiClient>);
|
|
}
|
|
|
|
beforeEach(() => vi.clearAllMocks());
|
|
|
|
describe('admin/users layout load', () => {
|
|
it('returns the users list', async () => {
|
|
mockApi([
|
|
{ id: 'u1', email: 'alice@example.com' },
|
|
{ id: 'u2', email: 'bob@example.com' }
|
|
]);
|
|
const result = await load({ fetch: vi.fn() as unknown as typeof fetch });
|
|
expect(result.users).toHaveLength(2);
|
|
expect(result.users[0].email).toBe('alice@example.com');
|
|
});
|
|
|
|
it('returns an empty array when the API returns nothing', async () => {
|
|
mockApi([]);
|
|
const result = await load({ fetch: vi.fn() as unknown as typeof fetch });
|
|
expect(result.users).toEqual([]);
|
|
});
|
|
|
|
it('calls GET /api/users', async () => {
|
|
const mockGet = vi.fn().mockResolvedValue({ response: { ok: true }, data: [] });
|
|
vi.mocked(createApiClient).mockReturnValue({ GET: mockGet } as ReturnType<
|
|
typeof createApiClient
|
|
>);
|
|
await load({ fetch: vi.fn() as unknown as typeof fetch });
|
|
expect(mockGet).toHaveBeenCalledWith('/api/users');
|
|
});
|
|
});
|