27 lines
1.4 KiB
JavaScript
27 lines
1.4 KiB
JavaScript
import { describe, it, expect, beforeAll, vi } from 'vitest';
|
|
import { pool } from '../../lib/db/pool.js';
|
|
import { resetDb } from '../helpers/db.js';
|
|
import { migrateUp } from '../../lib/db/migrate.js';
|
|
import { ensureSpace } from '../../migrate/spaces.js';
|
|
import { importKarakeep } from '../../migrate/sources/karakeep.js';
|
|
|
|
let spaceId;
|
|
beforeAll(async () => { await resetDb(); await migrateUp(); spaceId = await ensureSpace('bookmarks', 'Bookmarks'); });
|
|
|
|
describe('karakeep importer', () => {
|
|
it('imports bookmarks as url refs, idempotently', async () => {
|
|
const page = { bookmarks: [
|
|
{ id: 'b1', content: { type: 'link', url: 'https://a.test', title: 'A' } },
|
|
{ id: 'b2', content: { type: 'link', url: 'https://b.test', title: 'B' } }
|
|
], nextCursor: null };
|
|
const fetchImpl = vi.fn(async () => ({ ok: true, json: async () => page }));
|
|
const r1 = await importKarakeep({ apiUrl: 'http://k', token: 't', spaceId, fetchImpl });
|
|
expect(r1.created).toBe(2);
|
|
const { rows } = await pool.query(`SELECT source_url FROM refs WHERE space_id=$1 ORDER BY source_url`, [spaceId]);
|
|
expect(rows.map(r => r.source_url)).toEqual(['https://a.test', 'https://b.test']);
|
|
await importKarakeep({ apiUrl: 'http://k', token: 't', spaceId, fetchImpl }); // upsert, no dupes
|
|
const { rows: again } = await pool.query(`SELECT count(*)::int n FROM refs WHERE space_id=$1`, [spaceId]);
|
|
expect(again[0].n).toBe(2);
|
|
});
|
|
});
|