Skip to content

Commit 12ac08a

Browse files
authored
fix: prepare validated_at to be null when validation report is not returned (#1267)
1 parent 1ee3c9a commit 12ac08a

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

web-app/src/app/utils/date.spec.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,56 @@
1-
import { getTimeLeftForTokenExpiration } from './date';
1+
import { getTimeLeftForTokenExpiration, displayFormattedDate } from './date';
2+
3+
describe('displayFormattedDate', () => {
4+
test('returns empty string for null', () => {
5+
expect(displayFormattedDate(null as unknown as string)).toBe('');
6+
});
7+
8+
test('returns empty string for undefined', () => {
9+
expect(displayFormattedDate(undefined as unknown as string)).toBe('');
10+
});
11+
12+
test('returns empty string for empty string', () => {
13+
expect(displayFormattedDate('')).toBe('');
14+
});
15+
16+
test('returns empty string for invalid date string', () => {
17+
expect(displayFormattedDate('not-a-date')).toBe('');
18+
});
19+
20+
test('returns formatted string for valid ISO date', () => {
21+
const result = displayFormattedDate('2023-01-01T12:00:00Z');
22+
// Format manually to match expected UTC time
23+
expect(result).toBe(
24+
new Intl.DateTimeFormat('en-US', {
25+
dateStyle: 'medium',
26+
timeStyle: 'short',
27+
timeZone: 'UTC',
28+
}).format(new Date('2023-01-01T12:00:00Z')),
29+
);
30+
});
31+
32+
test('returns formatted string for valid date-only string', () => {
33+
const result = displayFormattedDate('2023-01-01');
34+
expect(result).toBe(
35+
new Intl.DateTimeFormat('en-US', {
36+
dateStyle: 'medium',
37+
timeStyle: 'short',
38+
timeZone: 'UTC',
39+
}).format(new Date('2023-01-01')),
40+
);
41+
});
42+
43+
test('returns formatted string for ISO with timezone offset', () => {
44+
const result = displayFormattedDate('2023-01-01T12:00:00-05:00');
45+
expect(result).toBe(
46+
new Intl.DateTimeFormat('en-US', {
47+
dateStyle: 'medium',
48+
timeStyle: 'short',
49+
timeZone: 'UTC',
50+
}).format(new Date('2023-01-01T12:00:00-05:00')),
51+
);
52+
});
53+
});
254

355
describe('getTimeLeftForTokenExpiration', () => {
456
const nowHours = 12;

web-app/src/app/utils/date.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { utcToZonedTime } from 'date-fns-tz';
22
import { intervalToDuration, isFuture } from 'date-fns';
33

4-
export const displayFormattedDate = (stringDate: string): string => {
4+
export const displayFormattedDate = (stringDate?: string): string => {
5+
if (stringDate == null) {
6+
return '';
7+
}
58
const date = new Date(stringDate);
9+
// Check if the date is valid
10+
if (isNaN(date.getTime())) {
11+
return '';
12+
}
613
return new Intl.DateTimeFormat('en-US', {
714
dateStyle: 'medium',
815
timeStyle: 'short',

0 commit comments

Comments
 (0)