오류 수정
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const dbQueryMock = vi.fn();
|
||||
const { dbQueryMock } = vi.hoisted(() => ({
|
||||
dbQueryMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../lib/database.js', () => ({
|
||||
db: {
|
||||
@@ -15,17 +17,25 @@ describe('resolveLinkTemplateId', () => {
|
||||
dbQueryMock.mockReset();
|
||||
});
|
||||
|
||||
it('returns null when the provided template id does not exist', async () => {
|
||||
dbQueryMock.mockResolvedValueOnce({ rows: [] });
|
||||
|
||||
await expect(resolveLinkTemplateId('00000000-0000-0000-0000-000000000000', null)).resolves.toBeNull();
|
||||
});
|
||||
|
||||
it('falls back to template slug when the provided id is not usable', async () => {
|
||||
it('falls back to the default template when the provided id does not exist', async () => {
|
||||
dbQueryMock.mockResolvedValueOnce({ rows: [] });
|
||||
dbQueryMock.mockResolvedValueOnce({ rows: [{ id: '11111111-1111-1111-1111-111111111111' }] });
|
||||
|
||||
await expect(resolveLinkTemplateId('00000000-0000-0000-0000-000000000000', null)).resolves.toBe('11111111-1111-1111-1111-111111111111');
|
||||
expect(dbQueryMock).toHaveBeenNthCalledWith(2, 'SELECT id FROM link_templates WHERE is_default = true LIMIT 1');
|
||||
});
|
||||
|
||||
it('uses the template slug when it can be resolved', async () => {
|
||||
dbQueryMock.mockResolvedValueOnce({ rows: [{ id: '11111111-1111-1111-1111-111111111111' }] });
|
||||
|
||||
await expect(resolveLinkTemplateId(null, 'default')).resolves.toBe('11111111-1111-1111-1111-111111111111');
|
||||
expect(dbQueryMock).toHaveBeenNthCalledWith(2, 'SELECT id FROM link_templates WHERE slug = $1 LIMIT 1', ['default']);
|
||||
expect(dbQueryMock).toHaveBeenCalledWith('SELECT id FROM link_templates WHERE slug = $1 LIMIT 1', ['default']);
|
||||
});
|
||||
|
||||
it('falls back to the default template when the provided template id is invalid', async () => {
|
||||
dbQueryMock.mockResolvedValueOnce({ rows: [{ id: '22222222-2222-2222-2222-222222222222' }] });
|
||||
|
||||
await expect(resolveLinkTemplateId('not-a-uuid', null)).resolves.toBe('22222222-2222-2222-2222-222222222222');
|
||||
expect(dbQueryMock).toHaveBeenCalledWith('SELECT id FROM link_templates WHERE is_default = true LIMIT 1');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user