diff --git a/tests/e2e/default/login/renew-token.wdio-spec.js b/tests/e2e/default/login/renew-token.wdio-spec.js index a82cfd824b2..2b647d33bc9 100644 --- a/tests/e2e/default/login/renew-token.wdio-spec.js +++ b/tests/e2e/default/login/renew-token.wdio-spec.js @@ -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 () => { @@ -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; } }); diff --git a/tests/integration/api/routing.spec.js b/tests/integration/api/routing.spec.js index 7f507bdfcb6..f4eae1c734b 100644 --- a/tests/integration/api/routing.spec.js +++ b/tests/integration/api/routing.spec.js @@ -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'); diff --git a/tests/utils.js b/tests/utils.js index f617ecfed87..602d20f6942 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -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 = { @@ -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); @@ -1347,4 +1363,7 @@ module.exports = { listenForApi, makeTempDir, SW_SUCCESSFUL_REGEX: /Service worker generated successfully/, + updatePermissions, + + ONE_YEAR_IN_S, };