28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { resetDb } from '../helpers/db.js';
|
|
import { migrateUp } from '../../lib/db/migrate.js';
|
|
import * as links from '../../lib/db/repos/links.js';
|
|
|
|
beforeEach(async () => { await resetDb(); await migrateUp(); });
|
|
|
|
describe('links repo', () => {
|
|
it('create + listFrom + listTo + remove', async () => {
|
|
const a = '11111111-1111-1111-1111-111111111111';
|
|
const b = '22222222-2222-2222-2222-222222222222';
|
|
const link = await links.create('project', a, 'page', b, 'mentions');
|
|
expect(link.relation).toBe('mentions');
|
|
expect(await links.listFrom('project', a)).toHaveLength(1);
|
|
expect(await links.listTo('page', b)).toHaveLength(1);
|
|
await links.remove(link.id);
|
|
expect(await links.listFrom('project', a)).toHaveLength(0);
|
|
});
|
|
|
|
it('idempotent on the unique tuple', async () => {
|
|
const a = '11111111-1111-1111-1111-111111111111';
|
|
const b = '22222222-2222-2222-2222-222222222222';
|
|
const l1 = await links.create('project', a, 'page', b, 'mentions');
|
|
const l2 = await links.create('project', a, 'page', b, 'mentions');
|
|
expect(l2.id).toBe(l1.id);
|
|
});
|
|
});
|