Skip to content

Commit

Permalink
Fix date calculation in userCtx cookie e2e tests (#8111)
Browse files Browse the repository at this point in the history
  • Loading branch information
dianabarsan authored and andrablaj committed Mar 21, 2023
1 parent 97fe3ac commit 46bb03f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
12 changes: 6 additions & 6 deletions tests/e2e/default/login/renew-token.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const loginPage = require('../../../page-objects/default/login/login.wdio.page')
const commonPage = require('../../../page-objects/default/common/common.wdio.page');
const moment = require('moment');
const browserPage = require('../../../utils/browser');
const chai = require('chai');
const utils = require('../../../utils');

describe('should renew token', async () => {

Expand All @@ -15,15 +15,15 @@ describe('should renew token', async () => {
await commonPage.waitForPageLoaded();

for (let counter = 0; counter < 3; counter++) {
const beforPageLoadTime = moment();
const beforePageLoadTime = moment().add(utils.ONE_YEAR_IN_S, 'seconds');
await browser.refresh();
await commonPage.waitForPageLoaded();
const afterPageLoadTime = moment();
const afterPageLoadTime = moment().add(utils.ONE_YEAR_IN_S, 'seconds');
const ctxExpiry = await getCtxCookieExpiry();

chai.expect(
ctxExpiry.isBetween(beforPageLoadTime.add(1, 'year'), afterPageLoadTime.add(1, 'year')),
`Failed for counter = ${counter}, ${ctxExpiry.toISOString()} ${beforPageLoadTime.toISOString()}`
expect(
ctxExpiry.isBetween(beforePageLoadTime, afterPageLoadTime),
`Failed for counter = ${counter}, ${ctxExpiry} ${beforePageLoadTime} ${afterPageLoadTime}`
).to.be.true;
}
});
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/api/routing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,9 @@ describe('routing', () => {

// check the expiry date is around a year away
const expiryValue = expires.split('=')[1];
const expiryDate = moment.utc(expiryValue).add(1, 'hour'); // add a small margin of error
expect(expiryDate.diff(now, 'months')).to.equal(12);
const expiryDate = moment.utc(expiryValue);
const nextYear = now.add(utils.ONE_YEAR_IN_S, 'second');
expect(expiryDate.diff(nextYear, 'hour')).to.equal(0); // add a small margin of error

// check the other properties
expect(samesite).to.equal('SameSite=Lax');
Expand Down
19 changes: 19 additions & 0 deletions tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ process.env.CERTIFICATE_MODE = constants.CERTIFICATE_MODE;
process.env.NODE_TLS_REJECT_UNAUTHORIZED=0; // allow self signed certificates
const auth = { username: constants.USERNAME, password: constants.PASSWORD };

const ONE_YEAR_IN_S = 31536000;

const PROJECT_NAME = 'cht-e2e';
const NETWORK = 'cht-net-e2e';
const services = {
Expand Down Expand Up @@ -132,6 +134,20 @@ const updateSettings = updates => {
});
});
};
const updatePermissions = async (roles, addPermissions, removePermissions = []) => {
const settings = await module.exports.getSettings();
addPermissions.forEach(permission => {
if (!settings.permissions[permission]) {
settings.permissions[permission] = [];
}
settings.permissions[permission].push(...roles);
});

removePermissions.forEach(permission => {
settings.permissions[permission] = [];
});
await module.exports.updateSettings({ permissions: settings.permissions }, true);
};

const revertTranslations = async () => {
const updatedTranslations = Object.keys(originalTranslations);
Expand Down Expand Up @@ -1347,4 +1363,7 @@ module.exports = {
listenForApi,
makeTempDir,
SW_SUCCESSFUL_REGEX: /Service worker generated successfully/,
updatePermissions,

ONE_YEAR_IN_S,
};

0 comments on commit 46bb03f

Please sign in to comment.