feat: add sqlite catalog web app
This commit is contained in:
@@ -2,6 +2,7 @@ import { mkdtemp, rm } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { CatalogDatabase } from '../src/database/store.js';
|
||||
import { runCatalog } from '../src/run/runCatalog.js';
|
||||
|
||||
let dir = '';
|
||||
@@ -86,4 +87,45 @@ describe('run orchestration', () => {
|
||||
'Typescale AI'
|
||||
]);
|
||||
});
|
||||
|
||||
it('can persist run output to SQLite through a database writer', async () => {
|
||||
const path = join(dir, 'catalog.sqlite');
|
||||
const db = new CatalogDatabase(path);
|
||||
db.migrate();
|
||||
|
||||
const result = await runCatalog({
|
||||
config: {
|
||||
gmail: { folder: 'Newsletters' },
|
||||
output: { name: 'Catalog', excel: { enabled: false } },
|
||||
stateFile: join(dir, 'state.json')
|
||||
},
|
||||
messages: [
|
||||
{
|
||||
id: 'msg-1',
|
||||
messageId: '<msg-1>',
|
||||
from: 'SQLite Weekly <sqlite@example.com>',
|
||||
date: '2026-05-17T00:00:00.000Z',
|
||||
html: '<h2>Databases</h2><a href="https://sqlite.example">SQLite Post</a> - Local data.'
|
||||
}
|
||||
],
|
||||
writers: [
|
||||
{
|
||||
write: async (payload) =>
|
||||
db.saveCatalogRun({
|
||||
mode: 'test',
|
||||
newslettersProcessed: 1,
|
||||
linksExtracted: payload.rows.length,
|
||||
sponsorCount: payload.sponsors.length,
|
||||
deadLinkCount: payload.deadLinks.length,
|
||||
errors: 0,
|
||||
...payload
|
||||
})
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
expect(result.linksExtracted).toBe(1);
|
||||
expect(db.count('link_occurrences')).toBe(1);
|
||||
db.close();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user