Skip to content

Commit

Permalink
Move test
Browse files Browse the repository at this point in the history
  • Loading branch information
enstulen committed Apr 2, 2024
1 parent 3d57769 commit f63fe5b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 57 deletions.

This file was deleted.

57 changes: 56 additions & 1 deletion packages/shared-domain/src/utils/date.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getIso8601String } from './date';
import { generateWeeklyPeriods, getIso8601String } from './date';

describe('date.ts', () => {
describe('getIso8601String', () => {
Expand All @@ -9,3 +9,58 @@ describe('date.ts', () => {
});
});
});

describe('generateWeeklyPeriods function', () => {
it('should return an empty array if no date is provided', () => {
const result = generateWeeklyPeriods();
expect(result).toEqual([]);
});

it('should return an array with one period when numberOfPeriods is not provided', () => {
const result = generateWeeklyPeriods('2024-03-01');
expect(result.length).toBe(1);
});

it('should return an array of weekly periods', () => {
const result = generateWeeklyPeriods('2023-03-01', 3);

const expectedPeriods = [
{
periodFrom: new Date('2023-02-28T23:00:00.000Z'), // Wednesday
periodTo: new Date('2023-03-04T23:00:00.000Z'), // Sunday
id: expect.any(String),
},
{
periodFrom: new Date('2023-03-05T23:00:00.000Z'), // Monday
periodTo: new Date('2023-03-11T23:00:00.000Z'), // Sunday
id: expect.any(String),
},
{
periodFrom: new Date('2023-03-12T23:00:00.000Z'), // Monday
periodTo: new Date('2023-03-18T23:00:00.000Z'), // Sunday
id: expect.any(String),
},
];
expect(result).toEqual(expectedPeriods);
});

it('should return an array with correct number of periods when number of periods is provided', () => {
const numberOfPeriods = 5;
const result = generateWeeklyPeriods('2023-03-01', numberOfPeriods);
expect(result.length).toEqual(numberOfPeriods);
});

it('should have todays date as the last periodTo', () => {
const today = new Date();
today.setHours(0, 0, 0, 0);

const tenDaysAgo = new Date(today);
tenDaysAgo.setDate(today.getDate() - 10);

const result = generateWeeklyPeriods(tenDaysAgo.toISOString(), 3);

const lastPeriodTo = new Date(result[result.length - 1].periodTo);

expect(lastPeriodTo.toISOString()).toEqual(today.toISOString());
});
});

0 comments on commit f63fe5b

Please sign in to comment.