Files
faunosteo/apps/app/tests/unit/lib.dates.test.ts
T
bchanot 51225cacf6 fix(app): grant expiry ends the chosen day in Paris; species order 0..9999 (V1-2.5 L2)
Owner checkpoint 2026-11-02: expiry 23:59:59.999 Europe/Paris (picker, validation, display), tests under non-Paris zones and DST days; M7 redefines create_species and update_inactive_species with the range check; pgTAP 015 and 022; « Relecteur ou relectrice »; object_conflict EN; setup key selectable, no Copy.
2026-11-02 21:29:33 +01:00

92 lines
2.6 KiB
TypeScript

import { afterAll, beforeAll, describe, it, expect } from 'vitest'
import {
endOfParisDayIso,
formatDate,
nowIso,
parisDateIso,
parisTomorrowIso,
todayIso,
} from '@/lib/dates'
describe('formatDate fr', () => {
it('formats "2026-05-18" as "18 mai 2026"', () => {
expect(formatDate('2026-05-18', 'fr')).toBe('18 mai 2026')
})
it('drops leading zero on the day', () => {
expect(formatDate('2026-01-03', 'fr')).toBe('3 janvier 2026')
})
})
describe('formatDate en', () => {
it('formats "2026-05-18" as "May 18, 2026"', () => {
expect(formatDate('2026-05-18', 'en')).toBe('May 18, 2026')
})
it('drops leading zero on the day', () => {
expect(formatDate('2026-01-03', 'en')).toBe('January 3, 2026')
})
})
describe('formatDate edge', () => {
it('throws on invalid ISO input', () => {
expect(() => formatDate('not-a-date', 'fr')).toThrow()
})
})
describe('todayIso', () => {
it('returns YYYY-MM-DD', () => {
expect(todayIso()).toMatch(/^\d{4}-\d{2}-\d{2}$/)
})
})
describe('nowIso', () => {
it('returns a full ISO instant', () => {
expect(nowIso()).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)
})
})
// A zone west and a zone east of Paris: the Paris rules never follow the device.
describe.each(['America/Los_Angeles', 'Pacific/Kiritimati'])(
'Paris days under the device zone %s',
(zone) => {
const previous = process.env.TZ
beforeAll(() => {
process.env.TZ = zone
expect(Intl.DateTimeFormat().resolvedOptions().timeZone).toBe(zone)
})
afterAll(() => {
if (previous === undefined) delete process.env.TZ
else process.env.TZ = previous
})
it.each([
['2026-01-15', '2026-01-15T22:59:59.999Z'],
['2026-07-15', '2026-07-15T21:59:59.999Z'],
['2026-03-28', '2026-03-28T22:59:59.999Z'],
['2026-03-29', '2026-03-29T21:59:59.999Z'],
['2026-10-25', '2026-10-25T22:59:59.999Z'],
])('endOfParisDayIso(%s) is %s', (day, instant) => {
expect(endOfParisDayIso(day)).toBe(instant)
})
it('refuses an impossible or malformed day', () => {
expect(() => endOfParisDayIso('2026-02-30')).toThrow()
expect(() => endOfParisDayIso('2026-1-5')).toThrow()
})
it('parisDateIso reads the Paris date', () => {
expect(parisDateIso(new Date('2026-11-02T23:30:00Z'))).toBe('2026-11-03')
})
it('parisTomorrowIso is the next Paris calendar day, DST included', () => {
expect(parisTomorrowIso(new Date('2026-03-28T22:30:00Z'))).toBe(
'2026-03-29',
)
expect(parisTomorrowIso(new Date('2026-03-28T23:30:00Z'))).toBe(
'2026-03-30',
)
})
},
)