feat(telemetry): exportTo writes events.jsonl + stats.md (#7 v0.2.3)
This commit is contained in:
@@ -172,3 +172,38 @@ describe('TelemetryService.readAllRecent', () => {
|
||||
expect(await svc.readAllRecent()).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('TelemetryService.exportTo', () => {
|
||||
let dir: string;
|
||||
let outDir: string;
|
||||
beforeEach(() => {
|
||||
dir = mkdtempSync(join(tmpdir(), 'inkling-telem-'));
|
||||
outDir = mkdtempSync(join(tmpdir(), 'inkling-export-'));
|
||||
});
|
||||
afterEach(() => {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
rmSync(outDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it('writes events.jsonl (concat) + stats.md to folder', async () => {
|
||||
writeFileSync(join(dir, 'events-2026-05-01.jsonl'),
|
||||
JSON.stringify({ ts: '2026-05-01T00:00:00.000Z', kind: 'capture', payload: { noteId: 'a', rawTextLength: 1, hasMedia: false } }) + '\n');
|
||||
const svc = new TelemetryService(dir, () => new Date('2026-05-01T12:00:00Z'), 14);
|
||||
const r = await svc.exportTo(outDir);
|
||||
expect(r.eventCount).toBe(1);
|
||||
expect(existsSync(join(outDir, 'events.jsonl'))).toBe(true);
|
||||
expect(existsSync(join(outDir, 'stats.md'))).toBe(true);
|
||||
const events = readFileSync(join(outDir, 'events.jsonl'), 'utf8').trim().split('\n');
|
||||
expect(events).toHaveLength(1);
|
||||
const stats = readFileSync(join(outDir, 'stats.md'), 'utf8');
|
||||
expect(stats).toContain('총 이벤트: 1');
|
||||
});
|
||||
|
||||
it('handles empty input — writes 0-event stats', async () => {
|
||||
const svc = new TelemetryService(dir, () => new Date('2026-05-01T12:00:00Z'), 14);
|
||||
const r = await svc.exportTo(outDir);
|
||||
expect(r.eventCount).toBe(0);
|
||||
expect(readFileSync(join(outDir, 'events.jsonl'), 'utf8')).toBe('');
|
||||
expect(readFileSync(join(outDir, 'stats.md'), 'utf8')).toContain('총 이벤트: 0');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user