Skip to content

Commit

Permalink
chore(#6250): remove request-promise-native from e2e tests (#9703)
Browse files Browse the repository at this point in the history
Updates e2e tests request to use built-in fetch instead of request-promise-native.
Removes sessions from e2e tests, these are not needed anymore.
Updates all (except 2) datasource e2e tests to query api directly. These tests required that global fetch had a session enabled to work, and stopped working once sessions were removed.

#6250
  • Loading branch information
dianabarsan authored Dec 13, 2024
1 parent 6ba0a7d commit 58a5e7d
Show file tree
Hide file tree
Showing 32 changed files with 496 additions and 538 deletions.
3 changes: 2 additions & 1 deletion tests/e2e/default/contacts/edit.wdio-spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const cloneDeep = require('lodash/cloneDeep');
const loginPage = require('@page-objects/default/login/login.wdio.page');
const commonPage = require('@page-objects/default/common/common.wdio.page');
const placeFactory = require('@factories/cht/contacts/place');
Expand All @@ -16,7 +17,7 @@ describe('Edit ', () => {

const offlineUserContact = personFactory.build({ name: CONTACT_NAME, parent: healthCenter });
const onlineUserContact = personFactory.build({ parent: healthCenter });
healthCenter.contact = offlineUserContact;
healthCenter.contact = cloneDeep(offlineUserContact);

const offlineUser = userFactory.build({
username: 'offline_user',
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/default/logging/logging.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ describe('audit log', () => {
continuous: false
};
const requestOptions = {
resolveWithFullResponse: true,
path: '/_replicator',
method: 'POST',
body
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/default/pwa/manifest.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('manifest.json', () => {
try {
await utils.deleteDoc('branding');
} catch (err) {
if (err.statusCode === 404) {
if (err.status === 404) {
return; // already not there - success!
}
throw err;
Expand All @@ -53,7 +53,7 @@ describe('manifest.json', () => {
try {
return await utils.getDoc('branding');
} catch (e) {
if (e.statusCode === 404) {
if (e.status === 404) {
return { _id: 'branding' };
}
throw e;
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/default/sms/rapidpro.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('RapidPro SMS Gateway', () => {
});
throw new Error('should have thrown');
} catch (err) {
expect(err.responseBody).to.eql({ code: 403, error: 'No incoming key configured' });
expect(err.body).to.eql({ code: 403, error: 'No incoming key configured' });
}
});

Expand All @@ -91,7 +91,7 @@ describe('RapidPro SMS Gateway', () => {
});
throw new Error('should have thrown');
} catch (err) {
expect(err.responseBody).to.eql({ code: 403, error: 'Missing authorization token' });
expect(err.body).to.eql({ code: 403, error: 'Missing authorization token' });
}
});

Expand All @@ -108,7 +108,7 @@ describe('RapidPro SMS Gateway', () => {
});
throw new Error('should have thrown');
} catch (err) {
expect(err.responseBody).to.eql({ code: 403, error: 'Incorrect token' });
expect(err.body).to.eql({ code: 403, error: 'Incorrect token' });
}
});

Expand All @@ -125,7 +125,7 @@ describe('RapidPro SMS Gateway', () => {
});
throw new Error('should have thrown');
} catch (err) {
expect(err.responseBody).to.eql({ code: 403, error: 'Missing authorization token' });
expect(err.body).to.eql({ code: 403, error: 'Missing authorization token' });
}
});

Expand All @@ -143,7 +143,7 @@ describe('RapidPro SMS Gateway', () => {
});
throw new Error('should have thrown');
} catch (err) {
expect(err.responseBody).to.eql({ code: 400, error: 'Message was not saved' });
expect(err.body).to.eql({ code: 400, error: 'Message was not saved' });
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('Create user for contacts', () => {
path: '/medic/login',
body: { user: username, password, locale: 'en' },
method: 'POST',
simple: false,
resolveWithFullResponse: true,
noAuth: true,
};
return utils.request(opts);
Expand All @@ -118,7 +118,7 @@ describe('Create user for contacts', () => {
const assertUserPasswordChanged = async (user) => {
// Cannot login because user's password has been automatically reset
const resp0 = await submitLoginRequest(user);
expect(resp0.statusCode).to.equal(401);
expect(resp0.status).to.equal(401);

// Update user's password to something we know
await utils.request({
Expand All @@ -129,7 +129,7 @@ describe('Create user for contacts', () => {

// Can login with new password
const resp1 = await submitLoginRequest({ ...user, password: DISABLED_USER_PASSWORD });
expect(resp1.statusCode).to.equal(302);
expect(resp1.status).to.equal(302);
};

const assertNewUserSettings = (newUserSettings, newContact, originalUser) => {
Expand Down Expand Up @@ -799,7 +799,7 @@ describe('Create user for contacts', () => {
expect(updatedOriginalContact.user_for_contact).to.be.undefined;
// Can still login as original user
const resp1 = await submitLoginRequest(ONLINE_USER);
expect(resp1.statusCode).to.equal(302);
expect(resp1.status).to.equal(302);
// New user not created
const newUserSettings = await utils.getUserSettings({ contactId: replacementContactId });
expect(newUserSettings).to.be.empty;
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/.mocharc-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const deepEqualInAnyOrder = require('deep-equal-in-any-order');
chai.use(chaiExclude);
chai.use(chaiAsPromised);
chai.use(deepEqualInAnyOrder);
chai.use(require('chai-shallow-deep-equal'));
global.expect = chai.expect;
global.chai = chai;

module.exports = {
allowUncaught: false,
Expand Down
1 change: 0 additions & 1 deletion tests/integration/api/controllers/all-docs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ describe('all_docs handler', () => {
const request = {
method: 'POST',
body: { keys },
headers: { 'Content-Type': 'application/json' }
};

return utils
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/api/controllers/bulk-docs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ describe('bulk-docs handler', () => {
}).then(result => {
chai.expect(result.length).to.equal(8);
chai.expect(result[0]).excluding('_rev').to.deep.equal(docs[0]);
chai.expect(result[1]).to.deep.nested.include({ 'responseBody.error': 'not_found' });
chai.expect(result[1]).to.deep.nested.include({ 'body.error': 'not_found' });
chai.expect(result[2]).excluding('_rev').to.deep.equal(existentDocs[2]);
chai.expect(result[3]).excluding('_rev').to.deep.equal(existentDocs[3]);
chai.expect(result[4]).excluding('_rev').to.deep.equal(existentDocs[0]);

chai.expect(result[5]).excluding('_rev').to.deep.equal(docs[5]);
chai.expect(result[6]).to.deep.nested.include({ 'responseBody.error': 'not_found' });
chai.expect(result[6]).to.deep.nested.include({ 'body.error': 'not_found' });
chai.expect(result[7]).excluding( ['_rev', '_id']).to.deep.equal(docs[7]);

return sUtils.waitForSentinel(ids).then(() => sUtils.getInfoDocs(ids));
Expand Down Expand Up @@ -757,12 +757,12 @@ describe('bulk-docs handler', () => {
chai.expect(results.length).to.equal(8);

chai.expect(results[0]).excluding('_rev').to.deep.equal(docs[0]);
chai.expect(results[1]).to.deep.nested.include({ 'responseBody.error': 'not_found' });
chai.expect(results[1]).to.deep.nested.include({ 'body.error': 'not_found' });
chai.expect(results[2]).excluding('_rev').to.deep.equal(existentDocs[2]);
chai.expect(results[3]).excluding('_rev').to.deep.equal(existentDocs[3]);
chai.expect(results[4]).excluding('_rev').to.deep.equal(existentDocs[0]);
chai.expect(results[5]).excluding('_rev').to.deep.equal(docs[5]);
chai.expect(results[6]).to.deep.nested.include({ 'responseBody.error': 'not_found' });
chai.expect(results[6]).to.deep.nested.include({ 'body.error': 'not_found' });
chai.expect(results[7]).excluding(['_rev', '_id']).to.deep.equal(docs[7]);
});
});
Expand Down Expand Up @@ -804,7 +804,7 @@ describe('bulk-docs handler', () => {
chai.expect(result[0]).to.include({ id: 'denied_report', error: 'forbidden' });
} else {
// CouchDB interprets this as an attachment POST request
chai.expect(result).to.deep.nested.include({ 'responseBody.error': 'method_not_allowed' });
chai.expect(result).to.deep.nested.include({ 'body.error': 'method_not_allowed' });
}
});
});
Expand Down Expand Up @@ -862,9 +862,9 @@ describe('bulk-docs handler', () => {
})
.then(results => {
chai.expect(results[0]).to.deep.equal(docs[0]);
chai.expect(results[1]).to.include({ statusCode: 404 });
chai.expect(results[1]).to.include({ status: 404 });
chai.expect(results[2]).to.deep.equal(docs[2]);
chai.expect(results[3]).to.include({ statusCode: 404 });
chai.expect(results[3]).to.include({ status: 404 });
});
});

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/api/controllers/bulk-get.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ describe('bulk-get handler', () => {
if (result.results) {
chai.expect(result.results.length).to.equal(0);
} else {
chai.expect(result.responseBody).to.equal('Server error');
chai.expect(result.body).to.equal('Server error');
}
});
});
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/api/controllers/changes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ describe('changes handler', () => {
})
.then(response => {
expect(response.headers).to.be.ok;
expect(response.headers['content-type']).to.equal('application/json');
expect(response.headers.server).to.be.ok;
expect(response.headers.get('content-type')).to.equal('application/json');
expect(response.headers.get('server')).to.be.ok;
});
});
});
Expand Down Expand Up @@ -316,7 +316,7 @@ describe('changes handler', () => {
if (result.results) {
return assertChangeIds(result, ...changesIDs, bobUserId);
}
expect(result.responseBody.error).to.equal('forbidden');
expect(result.body.error).to.equal('forbidden');
});
});
});
Expand Down
36 changes: 18 additions & 18 deletions tests/integration/api/controllers/contacts-by-phone.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ describe('Contacts by phone API', () => {
.request(noAuthRequestOptions)
.then(() => chai.assert.fail('Should not allow unauthenticated requests'))
.catch(err => {
chai.expect(err.statusCode).to.equal(401);
chai.expect(err.error).to.deep.include({ code: 401, error: 'unauthorized' });
chai.expect(err.status).to.equal(401);
chai.expect(err.body).to.deep.include({ code: 401, error: 'unauthorized' });
});
});

Expand All @@ -197,8 +197,8 @@ describe('Contacts by phone API', () => {
.request(noAuthRequestOptions)
.then(() => chai.assert.fail('Should not allow unauthenticated requests'))
.catch(err => {
chai.expect(err.statusCode).to.equal(401);
chai.expect(err.error).to.deep.include({ code: 401, error: 'unauthorized' });
chai.expect(err.status).to.equal(401);
chai.expect(err.body).to.deep.include({ code: 401, error: 'unauthorized' });
});
});
});
Expand All @@ -210,8 +210,8 @@ describe('Contacts by phone API', () => {
.request(offlineRequestOptions)
.then(() => chai.assert.fail('Should not allow offline users'))
.catch(err => {
chai.expect(err.statusCode).to.equal(403);
chai.expect(err.error).to.deep.include({ code: 403, error: 'forbidden' });
chai.expect(err.status).to.equal(403);
chai.expect(err.body).to.deep.include({ code: 403, error: 'forbidden' });
});
});

Expand All @@ -222,8 +222,8 @@ describe('Contacts by phone API', () => {
.request(offlineRequestOptions)
.then(() => chai.assert.fail('Should not allow offline users'))
.catch(err => {
chai.expect(err.statusCode).to.equal(403);
chai.expect(err.error).to.deep.include({ code: 403, error: 'forbidden' });
chai.expect(err.status).to.equal(403);
chai.expect(err.body).to.deep.include({ code: 403, error: 'forbidden' });
});
});
});
Expand All @@ -234,8 +234,8 @@ describe('Contacts by phone API', () => {
.request(onlineRequestOptions)
.then(() => chai.assert.fail('Should fail when no params'))
.catch(err => {
chai.expect(err.statusCode).to.equal(400);
chai.expect(err.error).to.deep.equal({
chai.expect(err.status).to.equal(400);
chai.expect(err.body).to.deep.equal({
error: 'bad_request',
reason: '`phone` parameter is required and must be a valid phone number'
});
Expand All @@ -248,8 +248,8 @@ describe('Contacts by phone API', () => {
.request(onlineRequestOptions)
.then(() => chai.assert.fail('Should fail when no params'))
.catch(err => {
chai.expect(err.statusCode).to.equal(400);
chai.expect(err.error).to.deep.equal({
chai.expect(err.status).to.equal(400);
chai.expect(err.body).to.deep.equal({
error: 'bad_request',
reason: '`phone` parameter is required and must be a valid phone number'
});
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('Contacts by phone API', () => {
.request(onlineRequestOptions)
.then(() => chai.assert.fail('Should 404 when not found'))
.catch(result => {
chai.expect(result.error).to.deep.equal({ error: 'not_found', reason: 'no matches found' });
chai.expect(result.body).to.deep.equal({ error: 'not_found', reason: 'no matches found' });
});
});

Expand All @@ -309,8 +309,8 @@ describe('Contacts by phone API', () => {
.request(onlineRequestOptions)
.then(() => chai.assert.fail('Should fail when no params'))
.catch(err => {
chai.expect(err.statusCode).to.equal(400);
chai.expect(err.error).to.deep.equal({
chai.expect(err.status).to.equal(400);
chai.expect(err.body).to.deep.equal({
error: 'bad_request',
reason: '`phone` parameter is required and must be a valid phone number'
});
Expand All @@ -323,8 +323,8 @@ describe('Contacts by phone API', () => {
.request(onlineRequestOptions)
.then(() => chai.assert.fail('Should fail with incorrect params'))
.catch(err => {
chai.expect(err.statusCode).to.equal(400);
chai.expect(err.error).to.deep.equal({
chai.expect(err.status).to.equal(400);
chai.expect(err.body).to.deep.equal({
error: 'bad_request',
reason: '`phone` parameter is required and must be a valid phone number'
});
Expand Down Expand Up @@ -369,7 +369,7 @@ describe('Contacts by phone API', () => {
.request(onlineRequestOptions)
.then(() => chai.assert.fail('Should 404 when not found'))
.catch(result => {
chai.expect(result.error).to.deep.equal({ error: 'not_found', reason: 'no matches found' });
chai.expect(result.body).to.deep.equal({ error: 'not_found', reason: 'no matches found' });
});
});

Expand Down
Loading

0 comments on commit 58a5e7d

Please sign in to comment.