Files
inkling/tests/unit/kstDate.test.ts
altair823 3cfa60bbba refactor(v026): #3+#19+#34 KST helper 통합 → src/shared/util/kstDate.ts
기존 src/main/util/kstDate.ts (2 함수) 를 shared 로 이동 + kstTodayAsDate 추가.
main + renderer 양쪽 import 가능. 6 callsite 통합:
- NoteRepository.findExpiredCandidates (todayInKstString → kstTodayIso)
- TelemetryService.todayKstIso (inline 제거)
- telemetryStats.kstDate (inline 제거)
- AiWorker.todayKstAsDate / todayKstAsIso (inline 제거)
- store.snoozeExpired + snoozeRecall (inline 제거 → nextKstMidnightMs)

API: kstTodayIso(now) / nextKstMidnightMs(now) / kstTodayAsDate(now)
+ KST_OFFSET_MS, DAY_MS 상수 export.

단위 +4 cases (boundary, format, midnight, asDate). 418 → 422.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 01:27:25 +09:00

64 lines
2.6 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { kstTodayIso, nextKstMidnightMs, kstTodayAsDate } from '@shared/util/kstDate.js';
describe('kstTodayIso', () => {
it('returns KST calendar date as YYYY-MM-DD', () => {
// 2026-05-01 12:00 UTC = 2026-05-01 21:00 KST
expect(kstTodayIso(new Date('2026-05-01T12:00:00Z'))).toBe('2026-05-01');
});
it('handles UTC→KST date rollover (UTC 23:30 → KST next day 08:30)', () => {
expect(kstTodayIso(new Date('2026-05-01T23:30:00Z'))).toBe('2026-05-02');
});
it('handles KST midnight exactly (UTC 15:00 = KST 00:00 next day)', () => {
expect(kstTodayIso(new Date('2026-05-01T15:00:00Z'))).toBe('2026-05-02');
});
it('boundary — UTC 14:59:59 still KST 23:59:59 same day', () => {
// KST 5/4 23:59:59 = UTC 5/4 14:59:59
const utcDate = new Date('2026-05-04T14:59:59Z');
expect(kstTodayIso(utcDate)).toBe('2026-05-04');
});
it('KST 5/5 00:30 (UTC 5/4 15:30) returns 2026-05-05', () => {
const utcDate = new Date('2026-05-04T15:30:00Z');
expect(kstTodayIso(utcDate)).toBe('2026-05-05');
});
});
describe('nextKstMidnightMs', () => {
it('returns the next KST 00:00 epoch ms (UTC 12:00 → +12h to KST midnight)', () => {
// 2026-05-01 12:00 UTC = 2026-05-01 21:00 KST → 다음 KST 자정 = 2026-05-02 00:00 KST
// = 2026-05-01 15:00 UTC
const now = Date.parse('2026-05-01T12:00:00Z');
const next = nextKstMidnightMs(now);
expect(new Date(next).toISOString()).toBe('2026-05-01T15:00:00.000Z');
});
it('returns 24h-from-now-ish when called shortly after KST midnight', () => {
// 2026-05-01 15:01 UTC = 2026-05-02 00:01 KST → 다음 KST 자정 = 2026-05-03 00:00 KST
// = 2026-05-02 15:00 UTC (≈ 23h59m later)
const now = Date.parse('2026-05-01T15:01:00Z');
const next = nextKstMidnightMs(now);
expect(new Date(next).toISOString()).toBe('2026-05-02T15:00:00.000Z');
expect(next - now).toBeGreaterThan(23 * 60 * 60 * 1000);
expect(next - now).toBeLessThan(24 * 60 * 60 * 1000);
});
it('KST 5/5 00:30 → next KST midnight = 5/6 00:00 KST = 5/5 15:00 UTC', () => {
const utcMs = new Date('2026-05-04T15:30:00Z').getTime();
const next = nextKstMidnightMs(utcMs);
expect(new Date(next).toISOString()).toBe('2026-05-05T15:00:00.000Z');
});
});
describe('kstTodayAsDate', () => {
it('returns UTC Date at KST 00:00', () => {
// KST 5/5 00:30 → KST 5/5 00:00 = UTC 5/4 15:00
const utcDate = new Date('2026-05-04T15:30:00Z');
const result = kstTodayAsDate(utcDate);
expect(result.toISOString()).toBe('2026-05-05T00:00:00.000Z');
});
});