refactor: reorganize shared/lib into per-function subfolders

This commit is contained in:
Ilia Mashkov
2026-04-24 11:41:43 +03:00
parent f3b4e1d064
commit 41edc7edf7
9 changed files with 5 additions and 5 deletions
@@ -0,0 +1,47 @@
import { formatYearRange } from './formatDate';
describe('formatYearRange', () => {
describe('Success Paths', () => {
it('formats a date range within the same year', () => {
const start = '2024-01-01 12:00:00.000Z';
const end = '2024-12-31 12:00:00.000Z';
expect(formatYearRange(start, end)).toBe('2024');
});
it('formats a range between different years', () => {
const start = '2021-05-15 12:00:00.000Z';
const end = '2024-03-20 12:00:00.000Z';
expect(formatYearRange(start, end)).toBe('2021 — 2024');
});
it('formats a range with null end date as "Present"', () => {
const start = '2022-08-01 12:00:00.000Z';
const end = null;
expect(formatYearRange(start, end)).toBe('2022 — Present');
});
});
describe('Error & Edge Cases', () => {
it('throws if start date is invalid', () => {
const start = 'not-a-date';
const end = '2024-01-01';
expect(() => formatYearRange(start, end)).toThrow('Invalid start date');
});
it('throws if end date is provided but invalid', () => {
const start = '2024-01-01';
const end = 'invalid';
expect(() => formatYearRange(start, end)).toThrow('Invalid end date');
});
it('throws if start year is after end year', () => {
const start = '2024-01-01';
const end = '2020-01-01';
expect(() => formatYearRange(start, end)).toThrow('Start year cannot be after end year');
});
it('handles empty strings by throwing', () => {
expect(() => formatYearRange('', null)).toThrow('Invalid start date');
});
});
});