vega-frontend-monorepo/libs/governance/src/utils/get-enactment-timestamp.spec.ts
Sam Keen d3cb3896f4
fix(1837): account for proposal vote and enactment deadlines being uncoupled (#2005)
* Fix/1837: Remove 2 seconds from proposal vote deadline on submission to ensure the deadline is always slightly below the maximum the API accepts

* fix(1837): Adjust for vote deadline and enactment deadline being decoupled in the API

* fix(1837): Removed unnecessary dependencies

* fix(1837): A couple of extra tests for get-enactment-timestamp

* fix(1837): propose-update-asset.tsx tweaked to ensure max enactment button works properly
2022-11-11 14:30:03 +00:00

61 lines
1.8 KiB
TypeScript

import { getEnactmentTimestamp } from './get-enactment-timestamp';
import { addHours, addMinutes, getTime, subSeconds } from 'date-fns';
beforeEach(() => {
jest.useFakeTimers();
jest.setSystemTime(0);
});
afterEach(() => {
jest.useRealTimers();
});
describe('getEnactmentTimestamp', () => {
it('should return the correct timestamp', () => {
const isMinimumVoteDeadlineSelected = false;
const isMaximumVoteDeadlineSelected = false;
const enactmentDeadline = '1';
const expected = Math.floor(
getTime(addHours(new Date(), Number(enactmentDeadline))) / 1000
);
const actual = getEnactmentTimestamp(
enactmentDeadline,
isMinimumVoteDeadlineSelected,
isMaximumVoteDeadlineSelected
);
expect(actual).toEqual(expected);
});
it('should return the correct timestamp when minimum vote deadline is selected', () => {
const isMinimumVoteDeadlineSelected = true;
const isMaximumVoteDeadlineSelected = false;
const enactmentDeadline = '1';
const expected = Math.floor(
getTime(addMinutes(addHours(new Date(), Number(enactmentDeadline)), 2)) /
1000
);
const actual = getEnactmentTimestamp(
enactmentDeadline,
isMinimumVoteDeadlineSelected,
isMaximumVoteDeadlineSelected
);
expect(actual).toEqual(expected);
});
it('should return the correct timestamp when maximum vote deadline is selected', () => {
const isMinimumVoteDeadlineSelected = false;
const isMaximumVoteDeadlineSelected = true;
const enactmentDeadline = '1';
const expected = Math.floor(
getTime(subSeconds(addHours(new Date(), Number(enactmentDeadline)), 2)) /
1000
);
const actual = getEnactmentTimestamp(
enactmentDeadline,
isMinimumVoteDeadlineSelected,
isMaximumVoteDeadlineSelected
);
expect(actual).toEqual(expected);
});
});