Skip to content

Commit

Permalink
fixup! fixup! test(staking): Add new test cases for dateParser new fu…
Browse files Browse the repository at this point in the history
…nction
  • Loading branch information
brunomenezes committed Jun 22, 2023
1 parent 37d7dbd commit 0a389af
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions apps/staking/__tests__/utils/dateParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
import { differenceInDays } from 'date-fns';
import {
getPastDaysInSeconds,
toUnixTimestamp,
Expand All @@ -26,41 +27,30 @@ describe('dateParser util', () => {
});

describe('date manipulation', () => {
const now = 1687417813360;
const today = new Date(1687417813360);

beforeEach(() => {
// jest.spyOn(Date, 'now').mockImplementation(() => now);
jest.spyOn(Date, 'now').mockImplementation(() => today.getTime());
});

afterEach(() => {
jest.clearAllMocks();
});

it('should return past days in seconds (7 days ago)', () => {
const expectedTimeInSeconds = 1686744000;
const resultInSeconds = getPastDaysInSeconds(7);

expect(new Date(now).toUTCString()).toEqual(
'Thu, 22 Jun 2023 07:10:13 GMT'
);
expect(new Date(resultInSeconds * 1000).toUTCString()).toEqual(
'Wed, 14 Jun 2023 12:00:00 GMT'
);
expect(resultInSeconds).toEqual(expectedTimeInSeconds);
expect(
differenceInDays(today, new Date(resultInSeconds * 1000))
).toEqual(7);
});

it('should return past days in seconds (30 days ago)', () => {
const expectedTimeInSeconds = 1684756800;
const resultInSeconds = getPastDaysInSeconds(30);

expect(new Date(now).toUTCString()).toEqual(
'Thu, 22 Jun 2023 07:10:13 GMT'
);
expect(new Date(resultInSeconds * 1000).toUTCString()).toEqual(
'Mon, 22 May 2023 12:00:00 GMT'
);

expect(resultInSeconds).toEqual(expectedTimeInSeconds);
expect(
differenceInDays(today, new Date(resultInSeconds * 1000))
).toEqual(30);
});
});
});

0 comments on commit 0a389af

Please sign in to comment.