code
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const dbQueryMock = vi.fn();
|
||||
|
||||
vi.mock('../lib/database.js', () => ({
|
||||
db: {
|
||||
query: dbQueryMock,
|
||||
},
|
||||
}));
|
||||
|
||||
import { resolveLinkTemplateId } from './links.js';
|
||||
|
||||
describe('resolveLinkTemplateId', () => {
|
||||
beforeEach(() => {
|
||||
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 () => {
|
||||
dbQueryMock.mockResolvedValueOnce({ rows: [] });
|
||||
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']);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user