mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
remove system time mock
This commit is contained in:
parent
5b175a71f9
commit
f541b0868c
@ -20,19 +20,22 @@ describe('API Token', () => {
|
|||||||
hexedString: '6170692d746f6b656e5f746573742d72616e646f6d2d6279746573',
|
hexedString: '6170692d746f6b656e5f746573742d72616e646f6d2d6279746573',
|
||||||
};
|
};
|
||||||
|
|
||||||
const now = Date.now();
|
let now;
|
||||||
|
let nowSpy;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest
|
jest
|
||||||
.spyOn(crypto, 'randomBytes')
|
.spyOn(crypto, 'randomBytes')
|
||||||
.mockImplementation(() => Buffer.from(mockedApiToken.randomBytes));
|
.mockImplementation(() => Buffer.from(mockedApiToken.randomBytes));
|
||||||
|
|
||||||
jest.useFakeTimers('modern').setSystemTime(now);
|
// To eliminate latency in the request and predict the expiry timestamp, we freeze Date.now()
|
||||||
|
now = Date.now();
|
||||||
|
nowSpy = jest.spyOn(Date, 'now').mockImplementation(() => now);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
|
nowSpy.mockRestore();
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
|
||||||
jest.useRealTimers();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
|
@ -27,19 +27,22 @@ describe('Transfer Token', () => {
|
|||||||
hexedString: '7472616e736665722d746f6b656e5f746573742d72616e646f6d2d6279746573',
|
hexedString: '7472616e736665722d746f6b656e5f746573742d72616e646f6d2d6279746573',
|
||||||
};
|
};
|
||||||
|
|
||||||
const now = Date.now();
|
let now;
|
||||||
|
let nowSpy;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest
|
jest
|
||||||
.spyOn(crypto, 'randomBytes')
|
.spyOn(crypto, 'randomBytes')
|
||||||
.mockImplementation(() => Buffer.from(mockedTransferToken.randomBytes));
|
.mockImplementation(() => Buffer.from(mockedTransferToken.randomBytes));
|
||||||
|
|
||||||
jest.useFakeTimers('modern').setSystemTime(now);
|
// To eliminate latency in the request and predict the expiry timestamp, we freeze Date.now()
|
||||||
|
now = Date.now();
|
||||||
|
nowSpy = jest.spyOn(Date, 'now').mockImplementation(() => now);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
|
nowSpy.mockRestore();
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
|
||||||
jest.useRealTimers();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user