Skip to content

Commit

Permalink
test(staking): Add new test cases for dateParser new function
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomenezes committed Jun 22, 2023
1 parent f00b490 commit dc29590
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion apps/staking/__tests__/utils/dateParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
// 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 { toUnixTimestamp } from '../../src/utils/dateParser';
import { differenceInDays } from 'date-fns';
import {
getPastDaysInSeconds,
toUnixTimestamp,
} from '../../src/utils/dateParser';

describe('dateParser util', () => {
it('should parse milliseconds', () => {
Expand All @@ -21,4 +25,32 @@ describe('dateParser util', () => {
Math.floor(time.getTime() / 1000)
);
});

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

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

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

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

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

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

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

0 comments on commit dc29590

Please sign in to comment.