refs #6264 perf: try to remove jasmine.clock()
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2023-11-30 07:32:16 +01:00
parent 97d7f8356f
commit d4cd23853f
3 changed files with 4 additions and 6 deletions

View File

@ -2,10 +2,8 @@ const tokenConfig = require('./token-config');
module.exports = async token => { module.exports = async token => {
const accessTokenConfig = await tokenConfig(); const accessTokenConfig = await tokenConfig();
let now = Date.now(); const now = Date.now();
if (Date?.vnNow !== undefined)
now = Date.vnNow();
const differenceMilliseconds = now - token.created; const differenceMilliseconds = now - token.created;
const differenceSeconds = Math.floor(differenceMilliseconds / 1000); const differenceSeconds = Math.floor(differenceMilliseconds / 1000);
return differenceSeconds > accessTokenConfig.renewPeriod - accessTokenConfig.courtesyTime; return differenceSeconds < accessTokenConfig.renewPeriod - accessTokenConfig.courtesyTime;
}; };

View File

@ -29,7 +29,7 @@ module.exports = Self => {
// Check if current token is valid // Check if current token is valid
const isValid = await Self.validateToken(token); const isValid = await Self.validateToken(token);
if (!isValid) throw new UserError(`The renew period has not been exceeded`, 'periodNotExceeded'); if (isValid) throw new UserError(`The renew period has not been exceeded`, 'periodNotExceeded');
const {courtesyTime} = await tokenConfig(); const {courtesyTime} = await tokenConfig();

View File

@ -29,13 +29,13 @@ describe('Validate Token', () => {
}); });
it('Token is not expired', async() => { it('Token is not expired', async() => {
jasmine.clock().mockDate(new Date(startingTime + 21600000));
const isValid = await models.VnUser.validateToken(ctx.req.accessToken); const isValid = await models.VnUser.validateToken(ctx.req.accessToken);
expect(isValid).toBeTrue(); expect(isValid).toBeTrue();
}); });
it('Token is expired', async() => { it('Token is expired', async() => {
jasmine.clock().mockDate(new Date(startingTime + 21600000));
const isValid = await models.VnUser.validateToken(ctx.req.accessToken); const isValid = await models.VnUser.validateToken(ctx.req.accessToken);
expect(isValid).toBeFalse(); expect(isValid).toBeFalse();