feat(repos): pages with auto-revisions, refs with upsertByExternal
This commit is contained in:
35
tests/repos/refs.test.js
Normal file
35
tests/repos/refs.test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { resetDb } from '../helpers/db.js';
|
||||
import { migrateUp } from '../../lib/db/migrate.js';
|
||||
import * as spaces from '../../lib/db/repos/spaces.js';
|
||||
import * as refs from '../../lib/db/repos/refs.js';
|
||||
|
||||
const owner = { kind: 'user', id: null };
|
||||
beforeEach(async () => { await resetDb(); await migrateUp(); });
|
||||
|
||||
describe('refs repo', () => {
|
||||
it('creates a url ref', async () => {
|
||||
const s = await spaces.create({ slug: 'h', name: 'H' }, owner);
|
||||
const r = await refs.create({
|
||||
space_id: s.id, kind: 'url',
|
||||
source_url: 'https://example.com',
|
||||
title: 'Ex', source_kind: 'manual'
|
||||
}, owner);
|
||||
expect(r.kind).toBe('url');
|
||||
expect(r.status).toBe('ingested');
|
||||
});
|
||||
|
||||
it('idempotent upsert by (source_kind, external_id)', async () => {
|
||||
const s = await spaces.create({ slug: 'h', name: 'H' }, owner);
|
||||
const r1 = await refs.upsertByExternal({
|
||||
space_id: s.id, kind: 'url', source_url: 'https://e.com',
|
||||
source_kind: 'karakeep', external_id: 'kk-123', title: 'v1'
|
||||
}, owner);
|
||||
const r2 = await refs.upsertByExternal({
|
||||
space_id: s.id, kind: 'url', source_url: 'https://e.com',
|
||||
source_kind: 'karakeep', external_id: 'kk-123', title: 'v2'
|
||||
}, owner);
|
||||
expect(r2.id).toBe(r1.id);
|
||||
expect(r2.title).toBe('v2');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user