forked from JhaSourav07/commitpulse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.empty-fallback.test.ts
More file actions
34 lines (28 loc) · 1.45 KB
/
Copy pathtime.empty-fallback.test.ts
File metadata and controls
34 lines (28 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* eslint-disable @typescript-eslint/no-explicit-any */
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
import { getSecondsUntilUTCMidnight, getSecondsUntilMidnightInTimezone } from './time';
describe('getSecondsUntilMidnightInTimezone - Edge Cases & Empty/Missing Inputs Verification', () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
it('1. falls back to UTC midnight calculation when tz is completely omitted', () => {
vi.setSystemTime(new Date('2024-06-15T12:00:00.000Z'));
expect(getSecondsUntilMidnightInTimezone()).toBe(getSecondsUntilUTCMidnight());
});
it('2. falls back to UTC midnight calculation when tz is undefined', () => {
vi.setSystemTime(new Date('2024-06-15T18:00:00.000Z'));
expect(getSecondsUntilMidnightInTimezone(undefined)).toBe(getSecondsUntilUTCMidnight());
});
it('3. falls back to UTC midnight calculation when tz is null', () => {
vi.setSystemTime(new Date('2024-06-15T20:30:00.000Z'));
expect(getSecondsUntilMidnightInTimezone(null as any)).toBe(getSecondsUntilUTCMidnight());
});
it('4. falls back to UTC midnight calculation when tz is empty or whitespace string', () => {
vi.setSystemTime(new Date('2024-06-15T23:59:00.000Z'));
expect(getSecondsUntilMidnightInTimezone('')).toBe(getSecondsUntilUTCMidnight());
expect(getSecondsUntilMidnightInTimezone(' ')).toBe(getSecondsUntilUTCMidnight());
});
});