refactor(test): replace as-cast with discriminant narrowing (review T7 I-1)

This commit is contained in:
altair823
2026-05-01 21:09:04 +09:00
parent 284bfcbdd1
commit c5329f1ccc

View File

@@ -146,7 +146,8 @@ describe('TelemetryService.readAllRecent', () => {
const svc = new TelemetryService(dir, () => new Date('2026-05-01T12:00:00Z'), 14);
const events = await svc.readAllRecent();
expect(events).toHaveLength(3);
expect(events.map((e) => (e.payload as { noteId: string }).noteId)).toEqual(['a', 'b', 'b']);
// discriminant narrowing — empty_trash 같은 noteId 없는 kind 가 섞이면 명시적으로 실패
expect(events.map((e) => e.kind === 'empty_trash' ? null : e.payload.noteId)).toEqual(['a', 'b', 'b']);
});
it('skips malformed lines (silent — invariant)', async () => {
@@ -157,7 +158,9 @@ describe('TelemetryService.readAllRecent', () => {
const svc = new TelemetryService(dir, () => new Date('2026-05-01T12:00:00Z'), 14);
const events = await svc.readAllRecent();
expect(events).toHaveLength(1);
expect((events[0]!.payload as { noteId: string }).noteId).toBe('a');
const ev = events[0]!;
expect(ev.kind).toBe('capture');
if (ev.kind !== 'empty_trash') expect(ev.payload.noteId).toBe('a');
});
it('returns [] when dir missing', async () => {