Skip to content

Commit

Permalink
chore(##8698): clean up and organize e2e tests: folders /about, /admi…
Browse files Browse the repository at this point in the history
…n, /analytics (#9355)

Co-authored-by: Maria Lorena Rodriguez Viruel <[email protected]>
  • Loading branch information
lorerod and lorena-medic authored Aug 27, 2024
1 parent 5343976 commit f6759ef
Show file tree
Hide file tree
Showing 71 changed files with 405 additions and 348 deletions.
6 changes: 3 additions & 3 deletions tests/e2e/default/admin/admin-access.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const adminPage = require('@page-objects/default/admin/admin.wdio.page');
const common = require('@page-objects/default/common/common.wdio.page');
const placeFactory = require('@factories/cht/contacts/place');

const offlineUser = userFactory.build({ username: 'offline-user-admin', isOffline: true });
const parent = placeFactory.place().build({ _id: 'dist1', type: 'district_hospital' });

describe('Acessing the admin app', () => {
const offlineUser = userFactory.build({ username: 'offline-user-admin', isOffline: true });
const parent = placeFactory.place().build({ _id: 'dist1', type: 'district_hospital' });

afterEach(async () => {
await browser.reloadSession();
await browser.url('/');
Expand Down
29 changes: 12 additions & 17 deletions tests/e2e/default/analytics/analytics.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ const chtConfUtils = require('@utils/cht-conf');
const chtDbUtils = require('@utils/cht-db');
const { TARGET_MET_COLOR, TARGET_UNMET_COLOR } = analyticsPage;

const updateSettings = async (settings) => {
await utils.updateSettings(settings, 'api');
await commonPage.sync(true);
await browser.refresh();
};

const compileTargets = async (targetsFileName = 'targets-config.js') => {
await chtConfUtils.initializeConfigDir();
const targetFilePath = path.join(__dirname, `config/${targetsFileName}`);

return chtConfUtils.compileNoolsConfig({ targets: targetFilePath });
};

describe('Targets', () => {
const places = placeFactory.generateHierarchy();
const healthCenter = places.get('health_center');
Expand All @@ -41,7 +28,14 @@ describe('Targets', () => {
parent: { _id: clinic._id, parent: clinic.parent }
});

const chw = userFactory.build({ place: healthCenter._id, roles: ['chw'], contact });
const chw = userFactory.build({ place: healthCenter._id, contact: contact });

const compileTargets = async (targetsFileName = 'targets-config.js') => {
await chtConfUtils.initializeConfigDir();
const targetFilePath = path.join(__dirname, `config/${targetsFileName}`);

return chtConfUtils.compileNoolsConfig({ targets: targetFilePath });
};

before(async () => {
await utils.saveDocs([...places.values(), owl]);
Expand Down Expand Up @@ -75,7 +69,8 @@ describe('Targets', () => {

it('should display correct message when no target found', async () => {
const settings = await compileTargets();
await updateSettings(settings);
await utils.updateSettings(settings, { ignoreReload: 'api', sync: true, refresh: true });

await analyticsPage.goToTargets();

const emptySelection = await analyticsPage.noSelectedTarget();
Expand All @@ -89,7 +84,7 @@ describe('Targets', () => {
const tasks = {
targets: { enabled: false }
};
await updateSettings({ tasks });
await utils.updateSettings({ tasks }, { ignoreReload: 'api', sync: true, refresh: true });
await analyticsPage.goToTargets();

const emptySelection = await analyticsPage.noSelectedTarget();
Expand All @@ -103,7 +98,7 @@ describe('Targets', () => {

it('should show error message for bad config', async () => {
const settings = await compileTargets('targets-error-config.js');
await updateSettings(settings);
await utils.updateSettings(settings, { ignoreReload: 'api', sync: true, refresh: true });
await analyticsPage.goToTargets();

const { errorMessage, url, username, errorStack } = await commonPage.getErrorLog();
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/default/contacts/add-custom-hierarchy.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ describe('Creating custom places', () => {
translations = customTypeFactory.translationKeys(contacts);
forms = customTypeFactory.formsForTypes(contacts, ngoCreateXML);
await utils.addTranslations('en', translations);
await utils.updateSettings({ contact_types: contacts }, true);
await utils.updateSettings({ contact_types: contacts }, { ignoreReload: true });

await utils.saveDocs(forms);
await login.cookieLogin();
});
Expand All @@ -82,7 +83,7 @@ describe('Creating custom places', () => {
settings.contact_types.push(secondTopLevel);
const forms = customTypeFactory.formsForTypes([secondTopLevel], ngoCreateXML);
await utils.revertSettings(true);
await utils.updateSettings({ contact_types: settings.contact_types }, true);
await utils.updateSettings({ contact_types: settings.contact_types }, { ignoreReload: true });
await utils.saveDocs(forms);
await login.cookieLogin();
await commonPage.goToPeople();
Expand Down
11 changes: 5 additions & 6 deletions tests/e2e/default/contacts/contact-details.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ describe('Contact details page.', () => {
const user = userFactory.build({username: 'offlineuser', roles: [ROLE]});
const patient = personFactory.build({parent: {_id: user.place._id, parent: {_id: parent._id}}});

const updateSettings = async (settings) => {
await utils.revertSettings(true);
await utils.updateSettings(settings, true);
};

const waitForContactLoaded = async (expectTasks) => {
await commonElements.waitForPageLoaded();
await contactPage.waitForContactLoaded();
Expand Down Expand Up @@ -81,7 +76,11 @@ describe('Contact details page.', () => {
removePermissions.forEach(permission => {
settings.permissions[permission] = settings.permissions[permission].filter(r => r !== roleValue);
});
await updateSettings({roles: settings.roles, permissions: settings.permissions});
await utils.updateSettings(
{ roles: settings.roles, permissions: settings.permissions },
{ revert: true, ignoreReload: true }
);

};

before(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('User Test Cases -> Creating Users ->', () => {
...settings.permissions,
can_have_multiple_places: [offlineUserRole],
};
await utils.updateSettings({ permissions }, true);
await utils.updateSettings({ permissions }, { ignoreReload: true });
await utils.saveDocs(docs);
await loginPage.cookieLogin();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Mute/Unmute contacts using a specific form - ', () => {

before(async () => {
await utils.saveDocs([...places.values(), person, mutePerson]);
await utils.updateSettings(settings_mute, true);
await utils.updateSettings(settings_mute, { ignoreReload: true });
await utils.createUsers([offlineUser]);
await loginPage.login(offlineUser);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Database access for new roles', () => {
roles.push(NEW_ROLE);
}
});
await utils.updateSettings(settings, true);
await utils.updateSettings(settings, { ignoreReload: true });
};

before(async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/db/ongoing-replication.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('ongoing replication', function() {

it('should download settings updates', async () => {
await commonPage.sync();
await utils.updateSettings({ test: true }, 'api');
await utils.updateSettings({ test: true }, { ignoreReload: 'api' });
await commonPage.sync(true);
const [settings] = await chtDbUtils.getDocs(['settings']);
expect(settings.settings.test).to.equal(true);
Expand Down
9 changes: 4 additions & 5 deletions tests/e2e/default/enketo/unauthorized-form.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ const utils = require('@utils');

describe('Unauthorized form', () => {

const updateSettings = async (customPlaceType, permissions = {}) => {
const updateUnauthorizedFormSettings = async (customPlaceType, permissions = {}) => {
const settings = await utils.getSettings();
const newSettings = {
contact_types: [ ...settings.contact_types, customPlaceType ],
permissions: { ...settings.permissions, ...permissions },
};
await utils.updateSettings(newSettings, true);
await commonPage.sync(true);
await utils.updateSettings(newSettings, { ignoreReload: true, sync: true });
};

const EXPECTED_UNAUTHORIZED_MESSAGE = 'Error loading form. Your user is not authorized to access this form. ' +
Expand Down Expand Up @@ -46,7 +45,7 @@ describe('Unauthorized form', () => {

it('should display unauthorized error message in contacts tab when user does not have form permission', async () => {
await commonPage.goToPeople();
await updateSettings(customPlaceType);
await updateUnauthorizedFormSettings(customPlaceType);

await commonPage.goToUrl(`#/contacts/add/${customPlaceType.id}`);
await commonPage.waitForPageLoaded();
Expand All @@ -56,7 +55,7 @@ describe('Unauthorized form', () => {

it('should not display unauthorized error message in contacts tab when user has the form permission', async () => {
await commonPage.goToPeople();
await updateSettings(customPlaceType, { can_create_clinic: [ 'chw' ] });
await updateUnauthorizedFormSettings(customPlaceType, { can_create_clinic: ['chw'] });

await commonPage.goToUrl(`#/contacts/add/${customPlaceType.id}`);
await commonPage.waitForPageLoaded();
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/login/token-login.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Token login', () => {
},
app_url: utils.getOrigin()
};
return utils.updateSettings(settings, true);
return utils.updateSettings(settings, { ignoreReload: true });
};

const createUser = (user) => {
Expand Down
13 changes: 5 additions & 8 deletions tests/e2e/default/purge/purge.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ describe('purge', function() {
.catch(callback);
});

const updateSettings = async (purgeFn, revert) => {
if (revert) {
await utils.revertSettings(true);
}
const updatePurgeSettings = async (purgeFn, revert) => {
const settings = { purge: { fn: purgeFn.toString(), text_expression: 'every 1 seconds', run_every_days: -1 } };
await utils.updateSettings(settings, true);
await utils.updateSettings(settings, { revert: revert, ignoreReload: true });
};

const runPurging = async () => {
Expand All @@ -79,7 +76,7 @@ describe('purge', function() {
});

it('purging runs on sync', async () => {
await updateSettings(filterPurgeReports); // settings should be at the beginning of the changes feed
await updatePurgeSettings(filterPurgeReports); // settings should be at the beginning of the changes feed

await utils.saveDocs([...places.values(), contact, patient]);
await utils.createUsers([user]);
Expand All @@ -96,7 +93,7 @@ describe('purge', function() {
expect(allReports.length).to.equal(homeVisits.length + pregnancies.length);
expect(allReports.map(r => r.form)).to.not.have.members(['purge']);

await updateSettings(filterHomeVisitReports, true);
await updatePurgeSettings(filterHomeVisitReports, true);
await runPurging();

await commonElements.sync(true);
Expand All @@ -109,7 +106,7 @@ describe('purge', function() {
});

it('purging runs when using chtScriptApi', async () => {
await updateSettings(filterByCht); // settings should be at the beginning of the changes feed
await updatePurgeSettings(filterByCht); // settings should be at the beginning of the changes feed

await utils.saveDocs([...places.values(), contact, patient]);
await utils.createUsers([user]);
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/reports/date-filter.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Report Filter', () => {
...settings.permissions,
can_view_old_filter_and_search: [ 'chw' ]
};
await utils.updateSettings({ permissions }, true);
await utils.updateSettings({ permissions }, { ignoreReload: true });

const results = await utils.saveDocs([ parent, patient, ...reports ]);
results.splice(0, 2); // Keeping only reports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('generating short codes', () => {

before(async () => {
await utils.saveDocs(docs);
await utils.updateSettings({forms, registrations, transitions}, true);
await utils.updateSettings({ forms, registrations, transitions }, { ignoreReload: true });

await loginPage.cookieLogin();
});
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/default/reports/reports-subject.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Reports Subject', () => {
};

before(async () => {
await utils.updateSettings(appSettings.WITH_SMS_FORMS, true);
await utils.updateSettings(appSettings.WITH_SMS_FORMS, { ignoreReload: true });
await utils.saveDocs([...places.values(), person]);
await utils.createUsers([user]);
await loginPage.cookieLogin();
Expand Down Expand Up @@ -341,7 +341,7 @@ describe('Reports Subject', () => {
});
});

it('changes to a loaded or list report should be reflected in the UI ', async () => {
it('changes to a loaded or list report should be reflected in the UI ', async () => {
const reportTest = {
_id: 'REF_REF_V3',
form: 'RR',
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/sms/link-to-patient.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const docs = [...places.values(), user];
describe('Link SMS to patient without passing id', () => {
before(async () => {
await utils.saveDocs(docs);
await utils.updateSettings({ forms, registrations, transitions, self_report }, true);
await utils.updateSettings({ forms, registrations, transitions, self_report }, { ignoreReload: true });
await loginPage.cookieLogin();
});

Expand Down
16 changes: 8 additions & 8 deletions tests/e2e/default/sms/rapidpro.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('RapidPro SMS Gateway', () => {
};

it('should fail with no incoming key configured', async () => {
await utils.updateSettings({ sms: smsSettings }, true);
await utils.updateSettings({ sms: smsSettings }, { ignoreReload: true });
try {
await utils.request({
path: endpoint,
Expand All @@ -81,7 +81,7 @@ describe('RapidPro SMS Gateway', () => {

it('should fail with no authentication provided', async () => {
await setIncomingKey();
await utils.updateSettings({ sms: smsSettings }, true);
await utils.updateSettings({ sms: smsSettings }, { ignoreReload: true });

try {
await utils.request({
Expand All @@ -97,7 +97,7 @@ describe('RapidPro SMS Gateway', () => {

it('should fail with incorrect authentication', async () => {
await setIncomingKey();
await utils.updateSettings({ sms: smsSettings }, true);
await utils.updateSettings({ sms: smsSettings }, { ignoreReload: true });

try {
await utils.request({
Expand All @@ -114,7 +114,7 @@ describe('RapidPro SMS Gateway', () => {

it('should fail with malformed authentication', async () => {
await setIncomingKey();
await utils.updateSettings({ sms: smsSettings }, true);
await utils.updateSettings({ sms: smsSettings }, { ignoreReload: true });

try {
await utils.request({
Expand All @@ -131,7 +131,7 @@ describe('RapidPro SMS Gateway', () => {

it('should fail when message was not created', async () => {
await setIncomingKey();
await utils.updateSettings({ sms: smsSettings }, true);
await utils.updateSettings({ sms: smsSettings }, { ignoreReload: true });

try {
await utils.request({
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('RapidPro SMS Gateway', () => {
};

await setIncomingKey();
await utils.updateSettings({ sms: smsSettings }, true);
await utils.updateSettings({ sms: smsSettings }, { ignoreReload: true });
const messageResult = await utils.request({
path: endpoint,
method: 'POST',
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('RapidPro SMS Gateway', () => {
};

await setIncomingKey();
await utils.updateSettings({ sms: smsSettings, forms }, true);
await utils.updateSettings({ sms: smsSettings, forms }, { ignoreReload: true });

const messageResult = await utils.request({
path: endpoint,
Expand Down Expand Up @@ -297,7 +297,7 @@ describe('RapidPro SMS Gateway', () => {
rapidpro: { url: utils.hostURL(server.address().port) },
}
};
await utils.updateSettings(settings, true);
await utils.updateSettings(settings, { ignoreReload: true });
});

afterEach(() => utils.revertDb([], true));
Expand Down
Loading

0 comments on commit f6759ef

Please sign in to comment.