Skip to content

Commit

Permalink
update e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
Benmuiruri committed Nov 18, 2024
1 parent 6c7d976 commit e0806e0
Show file tree
Hide file tree
Showing 62 changed files with 588 additions and 580 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
TAG: ${{ (github.ref_type == 'tag' && github.ref_name) || '' }}
BRANCH: ${{ github.head_ref || github.ref_name }}
BUILD_NUMBER: ${{ github.run_id }}
NODE_VERSION: '20.11'
NODE_VERSION: '22.11'

jobs:

Expand Down
4 changes: 1 addition & 3 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
FROM alpine:3.19 AS base_build
FROM node:22-alpine AS base_build

RUN apk add --update --no-cache \
build-base \
curl \
nodejs~=20 \
npm~=10 \
tzdata \
libxslt \
bash \
Expand Down
4 changes: 2 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"url": "git://github.com/medic/cht-core.git"
},
"engines": {
"node": ">=20.11.0",
"npm": ">=10.2.4"
"node": ">=22.11.0",
"npm": ">=10.9.0"
},
"scripts": {
"toc": "doctoc --github --maxlevel 2 README.md",
Expand Down
12 changes: 8 additions & 4 deletions api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,27 @@ process
await migrations.run();
logger.info('Database migrations completed successfully');

startupLog.start('forms');
logger.info('Generating manifest');
await manifest.generate();
logger.info('Manifest generated successfully');

logger.info('Generating service worker');
await generateServiceWorker.run(true);
logger.info('Service worker generated successfully');
} catch (err) {
logger.error('Fatal error initialising API');
logger.error('%o', err);
process.exit(1);
}

try {
startupLog.start('forms');
logger.info('Updating xforms…');
await generateXform.updateAll();
logger.info('xforms updated successfully');

} catch (err) {
logger.error('Fatal error initialising API');
logger.error('Error initialising API');
logger.error('%o', err);
process.exit(1);
}

startupLog.complete();
Expand Down
10 changes: 8 additions & 2 deletions api/src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ module.exports = {

checkPasswordChange: async (req) => {
if (!req.userCtx || !req.userCtx.name) {
throw { code: 401, message: 'Not logged in' };
const error = new Error('Not logged in');
error.code = 401;
error.error = 'Not logged in';
throw error;
}

if (req.url.includes('/password-reset')) {
Expand All @@ -91,7 +94,10 @@ module.exports = {

const user = await users.getUserDoc((req.userCtx.name));
if (user.password_change_required) {
throw { code: 403, message: 'Password change required' };
const error = new Error('Password change required');
error.code = 403;
error.error = 'Password change required';
throw error;
}
return true;
},
Expand Down
43 changes: 30 additions & 13 deletions api/src/controllers/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,30 @@ const validateCurrentPassword = async (username, currentPassword, newPassword) =
}
};

const passwordResetValidation = async (username, currentPassword, password) => {
const validation = validatePasswordReset(password);
if (!validation.isValid) {
return {
isValid: false,
status: 400,
error: validation.error,
params: validation.params
};
}

const currentPasswordValidation = await validateCurrentPassword(username, currentPassword, password);
if (!currentPasswordValidation.isValid) {
return {
isValid: false,
status: 400,
error: currentPasswordValidation.error
};
}

return { isValid: true };
};


module.exports = {
renderLogin,
renderPasswordReset,
Expand Down Expand Up @@ -510,26 +534,19 @@ module.exports = {

try {
const { username, currentPassword, password } = req.body;
const validation = validatePasswordReset(password);
if (!validation.isValid) {
return res.status(400).json({
error: validation.error,
params: validation.params,
});
}
const currentPasswordValidation = await validateCurrentPassword(username, currentPassword, password);
if (!currentPasswordValidation.isValid) {
return res.status(400).json({
error: currentPasswordValidation.error
const validationResult = await passwordResetValidation(username, currentPassword, password);
if (!validationResult.isValid) {
return res.status(validationResult.status).json({
error: validationResult.error,
params: validationResult.params
});
}

const userDoc = await db.users.get(`org.couchdb.user:${username}`);
await updatePassword(userDoc, password);

const { sessionCookie, userCtx } = await createNewSession(username, password);

const redirectUrl = await redirectToApp({ req, res, sessionCookie, userCtx });

return res.status(302).send(redirectUrl);
} catch (err) {
logger.error('Error updating password: %o', err);
Expand Down
5 changes: 0 additions & 5 deletions api/tests/mocha/services/async-storage.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
const sinon = require('sinon');
const rewire = require('rewire');
const { expect } = require('chai');
const asyncHooks = require('node:async_hooks');
const request = require('@medic/couch-request');
const serverUtils = require('../../../src/server-utils');

describe('async-storage', () => {
let service;
let asyncLocalStorage;

beforeEach(() => {
asyncLocalStorage = sinon.spy(asyncHooks, 'AsyncLocalStorage');
sinon.stub(request, 'initialize');
});

Expand All @@ -20,8 +17,6 @@ describe('async-storage', () => {

it('should initialize async storage and initialize couch-request', async () => {
service = rewire('../../../src/services/async-storage');

expect(asyncLocalStorage.callCount).to.equal(1);
expect(request.initialize.args).to.deep.equal([[
service,
serverUtils.REQUEST_ID_HEADER
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"url": "git://github.com/medic/cht-core.git"
},
"engines": {
"node": ">=20.11.0",
"npm": ">=10.2.4"
"node": ">=22.11.0",
"npm": ">=10.9.0"
},
"workspaces": [
"./shared-libs/*"
Expand Down
4 changes: 2 additions & 2 deletions scripts/deploy/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scripts/deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"test": "tests"
},
"engines": {
"node": ">=20.11.0",
"npm": ">=10.2.4"
"node": ">=22.11.0",
"npm": ">=10.9.0"
},
"bin": {
"cht-deploy": "./cht-deploy",
Expand Down
4 changes: 1 addition & 3 deletions sentinel/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
FROM alpine:3.19 AS base_build
FROM node:22-alpine AS base_build

RUN apk add --update --no-cache \
build-base \
curl \
nodejs~=20 \
npm~=10 \
tzdata \
bash \
jq
Expand Down
4 changes: 2 additions & 2 deletions sentinel/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sentinel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"private": true,
"version": "0.1.0",
"engines": {
"node": ">=20.11.0",
"npm": ">=10.2.4"
"node": ">=22.11.0",
"npm": ">=10.9.0"
},
"scripts": {
"run-watch": "TZ=UTC nodemon --inspect=0.0.0.0:9228 --watch server.js --watch 'src/**' --watch '../shared-libs/**/src/**' --watch '../shared-libs/**/dist/**' server.js"
Expand Down
32 changes: 16 additions & 16 deletions tests/e2e/default-mobile/navigation/more-options-menu.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('More Options Menu - Offline User', () => {
describe('Message tab', () => {
it('should hide the kebab menu.', async () => {
await sms.sendSms('testing', contact.phone);
expect(await (await commonPage.moreOptionsMenu()).isExisting()).to.be.false;
expect(await commonPage.isMoreOptionsMenuPresent()).to.be.false;
});
});

Expand All @@ -73,44 +73,44 @@ describe('More Options Menu - Offline User', () => {
await commonPage.goToPeople();
await contactsPage.selectLHSRowByText(patient.name);
await commonPage.openMoreOptionsMenu();
expect(await commonPage.isMenuOptionVisible('export', 'contacts')).to.be.false;
expect(await commonPage.isMenuOptionEnabled('edit', 'contacts')).to.be.true;
expect(await commonPage.isMenuOptionEnabled('delete', 'contacts')).to.be.true;
expect(await commonPage.isMenuOptionVisible('export')).to.be.false;
expect(await commonPage.isMenuOptionEnabled('edit')).to.be.true;
expect(await commonPage.isMenuOptionEnabled('delete')).to.be.true;
});

it('should hide the \'export\' and \'edit\' options and ' +
'disable the \'delete\' option when the offline user\'s place is selected', async () => {
await commonPage.goToPeople();
await contactsPage.selectLHSRowByText(health_center.name);
await commonPage.openMoreOptionsMenu();
expect(await commonPage.isMenuOptionVisible('export', 'contacts')).to.be.false;
expect(await commonPage.isMenuOptionVisible('edit', 'contacts')).to.be.false;
expect(await commonPage.isMenuOptionEnabled('delete', 'contacts')).to.be.false;
expect(await commonPage.isMenuOptionVisible('export')).to.be.false;
expect(await commonPage.isMenuOptionVisible('edit')).to.be.false;
expect(await commonPage.isMenuOptionEnabled('delete')).to.be.false;
});
});

describe('Report tab', () => {
it('should hide the \'export\' and \'edit\' options and ' +
'enable the \'delete\' and \'review\' options when the sms report is opened', async () => {
await commonPage.goToReports();
expect(await (await commonPage.moreOptionsMenu()).isExisting()).to.be.false;
expect(await commonPage.isMoreOptionsMenuPresent()).to.be.false;

await reportPage.goToReportById(smsReportId);
await commonPage.openMoreOptionsMenu();
expect(await commonPage.isMenuOptionVisible('export', 'reports')).to.be.false;
expect(await commonPage.isMenuOptionVisible('edit', 'reports')).to.be.false;
expect(await commonPage.isMenuOptionEnabled('delete', 'reports')).to.be.true;
expect(await commonPage.isMenuOptionEnabled('review', 'report')).to.be.true;
expect(await commonPage.isMenuOptionVisible('export')).to.be.false;
expect(await commonPage.isMenuOptionVisible('edit',)).to.be.false;
expect(await commonPage.isMenuOptionEnabled('delete')).to.be.true;
expect(await commonPage.isMenuOptionEnabled('review')).to.be.true;
});

it('should hide the \'export\' option and ' +
'enable the \'edit\', \'delete\' and \'review\' options when the xml report is opened', async () => {
await reportPage.goToReportById(xmlReportId);
await commonPage.openMoreOptionsMenu();
expect(await commonPage.isMenuOptionVisible('export', 'reports')).to.be.false;
expect(await commonPage.isMenuOptionEnabled('edit', 'reports')).to.be.true;
expect(await commonPage.isMenuOptionEnabled('delete', 'reports')).to.be.true;
expect(await commonPage.isMenuOptionEnabled('review', 'report')).to.be.true;
expect(await commonPage.isMenuOptionVisible('export')).to.be.false;
expect(await commonPage.isMenuOptionEnabled('edit')).to.be.true;
expect(await commonPage.isMenuOptionEnabled('delete')).to.be.true;
expect(await commonPage.isMenuOptionEnabled('review')).to.be.true;
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const pregnancyFactory = require('@factories/cht/reports/pregnancy');
const loginPage = require('@page-objects/default/login/login.wdio.page');
const oldNavigationPage = require('@page-objects/default/old-navigation/old-navigation.wdio.page');
const messagesPage = require('@page-objects/default/sms/messages.wdio.page');
const commonPage = require('@page-objects/default/common/common.wdio.page');
const taskPage = require('@page-objects/default/tasks/tasks.wdio.page');
const reportsPage = require('@page-objects/default/reports/reports.wdio.page');
const contactPage = require('@page-objects/default/contacts/contacts.wdio.page');
Expand Down Expand Up @@ -56,7 +55,7 @@ describe('Old Navigation', () => {
await messagesPage.sendMessageOnMobile(message, person.name, person.phone );
await messagesPage.openMessage(person._id);

const { name } = await commonPage.getHeaderTitleOnMobile();
const { name } = await oldNavigationPage.getHeaderTitleOnMobile();
expect(name).to.equal(person.name);

const messages = await messagesPage.getAmountOfMessagesByPhone();
Expand All @@ -71,7 +70,7 @@ describe('Old Navigation', () => {
pregnancyReport._id,
'~pregnancy-danger-sign-follow-up~anc.pregnancy_danger_sign_followup'
);
const { name } = await commonPage.getHeaderTitleOnMobile();
const { name } = await oldNavigationPage.getHeaderTitleOnMobile();
expect(name).to.equal('Pregnancy danger sign follow-up');
});

Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/default-mobile/reports/send-message.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const placeFactory = require('@factories/cht/contacts/place');
const userFactory = require('@factories/cht/users/users');
const personFactory = require('@factories/cht/contacts/person');
const loginPage = require('@page-objects/default/login/login.wdio.page');
const commonElements = require('@page-objects/default/common/common.wdio.page');
const commonPage = require('@page-objects/default/common/common.wdio.page');
const reportsPage = require('@page-objects/default/reports/reports.wdio.page');
const pregnancyFactory = require('@factories/cht/reports/pregnancy');

Expand Down Expand Up @@ -39,12 +39,12 @@ describe('Report - Send message action', () => {
});

it('should display option to send message', async () => {
await commonElements.goToReports();
await commonPage.goToReports();
const firstReport = await reportsPage.leftPanelSelectors.firstReport();
await reportsPage.openSelectedReport(firstReport);

expect(await commonElements.isReportActionDisplayed()).to.equal(true);
expect(await commonElements.reportsFastActionFAB().getAttribute('class'))
expect(await commonPage.isReportActionDisplayed()).to.equal(true);
expect(await commonPage.fabSelectors.reportsFastActionFAB().getAttribute('class'))
.to.include('fa-envelope');
});
});
1 change: 1 addition & 0 deletions tests/e2e/default-mobile/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports.config = Object.assign(wdioBaseConfig.config, {
'../default/navigation/navigation.wdio-spec.js',
'../default/reports/delete.wdio-spec.js',
'../default/enketo/training-cards.wdio-spec.js',
'./**/more-options-menu.wdio-spec.js',
]
},
beforeSuite: async () => {
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/default/admin/admin-access.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ describe('Accessing the admin app', () => {
await common.waitForLoaders();
await browser.url('/admin/#/forms');
expect(await (await adminPage.adminNavbarLogo()).isDisplayed()).to.equal(false);
expect(await common.jsonError()).to.equal(error);
expect(await common.getJsonErrorText()).to.equal(error);

await browser.url('/admin');
expect(await (await adminPage.adminNavbarLogo()).isDisplayed()).to.equal(false);
expect(await common.jsonError()).to.equal(error);
expect(await common.getJsonErrorText()).to.equal(error);

await browser.url('/medic/_design/medic-admin/_rewrite/');
expect(await (await adminPage.adminNavbarLogo()).isDisplayed()).to.equal(false);
expect(await common.jsonError()).to.equal(error);
expect(await common.getJsonErrorText()).to.equal(error);

await browser.url('/medic/_design/medic-admin/_rewrite/#/authorization/permissions');
expect(await (await adminPage.adminNavbarLogo()).isDisplayed()).to.equal(false);
expect(await common.jsonError()).to.equal(error);
expect(await common.getJsonErrorText()).to.equal(error);
});

it('should allow admins to access the page', async () => {
Expand Down
Loading

0 comments on commit e0806e0

Please sign in to comment.