Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4445 - Cache UserSettings() lookup of org.couchdb.user #4988

Merged
merged 11 commits into from
Nov 26, 2018
2 changes: 2 additions & 0 deletions tests/base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BaseConfig {
}

browser.driver.wait(setupSettings, 5 * 1000, 'Settings should be setup within 5 seconds');
browser.driver.wait(utils.setUserContactDoc, 5 * 1000, 'User contact should be setup within 5 seconds');
browser.driver.wait(setupUser, 5 * 1000, 'User should be setup within 5 seconds');
browser.driver.sleep(1); // block until previous command has completed

Expand Down Expand Up @@ -82,6 +83,7 @@ const setupSettings = () => {
const setupUser = () => {
return utils.getDoc('org.couchdb.user:' + auth.user)
.then(doc => {
doc.contact_id = constants.USER_CONTACT_ID;
doc.known = true;
doc.language = 'en';
doc.roles = ['_admin'];
Expand Down
10 changes: 9 additions & 1 deletion tests/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ module.exports = {

// test database to avoid writing to the dev db
DB_NAME: 'medic-test',
MAIN_DDOC_NAME: 'medic'
MAIN_DDOC_NAME: 'medic',

// tests create a document with this id to be referenced by org.couchdb.user contact_id
USER_CONTACT_ID: 'e2e_contact_test_id',

DEFAULT_USER_CONTACT_DOC: {
_id: 'e2e_contact_test_id',
type: 'person',
reported_date: 1541679811408,
},
};
5 changes: 2 additions & 3 deletions tests/e2e/forms/family-survey-form.specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ const familyForm = require('../../page-objects/forms/family-survey-form.po'),
userData = require('../../page-objects/forms/data/user.po.data');

describe('Family Survey form', () => {
const contactId = userData.contactId;
const docs = userData.docs;
const { userContactDoc, docs } = userData;
kennsippell marked this conversation as resolved.
Show resolved Hide resolved

beforeAll(done => {
protractor.promise
.all(docs.map(utils.saveDoc))
.then(() => familyForm.configureForm(contactId, done))
.then(() => familyForm.configureForm(userContactDoc, done))
.catch(done.fail);
});

Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/forms/submit-delivery-form.specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ const helper = require('../../helper'),
userData = require('../../page-objects/forms/data/user.po.data');

describe('Submit Delivery Report', () => {
const contactId = userData.contactId;
const docs = userData.docs;
const { userContactDoc, docs } = userData;
const noteToCHW =
'Good news, Jack! Jack () has delivered at the health facility. We will alert you when it is time to refer them for PNC. Please monitor them for danger signs. Thank you!';

beforeAll(done => {
protractor.promise
.all(docs.map(utils.saveDoc))
.then(() => deliveryReport.configureForm(contactId, done))
.then(() => deliveryReport.configureForm(userContactDoc, done))
.catch(done.fail);
});

Expand Down
11 changes: 5 additions & 6 deletions tests/e2e/forms/submit-photo-upload-form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const helper = require('../../helper'),
photoUpload = require('../../page-objects/forms/photo-upload.po'),
common = require('../../page-objects/common/common.po'),
utils = require('../../utils'),
constants = require('../../constants'),
path = require('path');

const contactId = 'some_contact_id';
const doc = {
_id: contactId,
const userContactDoc = {
_id: constants.USER_CONTACT_ID,
name: 'Jack',
date_of_birth: '',
phone: '+64274444444',
Expand All @@ -21,9 +21,8 @@ const doc = {

describe('Submit Photo Upload form', () => {
beforeAll(done => {
utils
.saveDoc(doc)
.then(() => photoUpload.configureForm(contactId, done))
Promise.resolve()
.then(() => photoUpload.configureForm(userContactDoc, done))
.catch(done.fail);
});

Expand Down
11 changes: 5 additions & 6 deletions tests/e2e/forms/submit-z-score-form.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const helper = require('../../helper'),
ZScoreForm = require('../../page-objects/forms/z-score.po'),
constants = require('../../constants'),
utils = require('../../utils');

const contactId = 'some_contact_id';
const doc = {
_id: contactId,
const userContactDoc = {
_id: constants.USER_CONTACT_ID,
name: 'Jack',
date_of_birth: '',
phone: '+64274444444',
Expand All @@ -19,9 +19,8 @@ const doc = {

describe('Submit Z-Score form', () => {
beforeAll(done => {
utils
.saveDoc(doc)
.then(() => ZScoreForm.configureForm(contactId, done))
Promise.resolve()
.then(() => ZScoreForm.configureForm(userContactDoc, done))
.catch(done.fail);
});

Expand Down
56 changes: 29 additions & 27 deletions tests/e2e/submit-enketo-form.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const utils = require('../utils'),
helper = require('../helper'),
constants = require('../constants'),
commonElements = require('../page-objects/common/common.po.js');

describe('Submit Enketo form', () => {
Expand All @@ -22,7 +23,7 @@ describe('Submit Enketo form', () => {
</h:body>
</h:html>`;

const contactId = '3b3d50d275280d2568cd36281d00348b';
const contactId = constants.USER_CONTACT_ID;

const docs = [
{
Expand Down Expand Up @@ -55,38 +56,39 @@ describe('Submit Enketo form', () => {
external_id: '',
type: 'district_hospital',
},
{
_id: contactId,
name: 'Jack',
date_of_birth: '',
phone: '+64274444444',
alternate_phone: '',
];

const userContactDoc = {
_id: contactId,
name: 'Jack',
date_of_birth: '',
phone: '+64274444444',
alternate_phone: '',
notes: '',
type: 'person',
reported_date: 1478469976421,
parent: {
_id: 'c49385b3594af7025ef097114104ef48',
reported_date: 1469578114543,
notes: '',
type: 'person',
reported_date: 1478469976421,
parent: {
_id: 'c49385b3594af7025ef097114104ef48',
reported_date: 1469578114543,
contact: {
_id: contactId,
name: 'Jack',
date_of_birth: '',
phone: '+64274444444',
alternate_phone: '',
notes: '',
contact: {
_id: contactId,
name: 'Jack',
date_of_birth: '',
phone: '+64274444444',
alternate_phone: '',
notes: '',
type: 'person',
reported_date: 1478469976421,
},
name: 'Number three district',
external_id: '',
type: 'district_hospital',
type: 'person',
reported_date: 1478469976421,
},
name: 'Number three district',
external_id: '',
type: 'district_hospital',
},
];
};

beforeAll(done => {
utils.seedTestData(done, contactId, docs);
utils.seedTestData(done, userContactDoc, docs);
});

afterEach(utils.afterEach);
Expand Down
65 changes: 32 additions & 33 deletions tests/page-objects/forms/data/user.po.data.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
const constants = require('../../../constants');

module.exports = {
contactId: '3b3d50d275280d2568cd36281d00348b',
docs: [
{
docs: [{
_id: 'c49385b3594af7025ef097114104ef48',
reported_date: 1469578114543,
notes: '',
contact: {
_id: constants.USER_CONTACT_ID,
name: 'Jack',
date_of_birth: '',
phone: '+64274444444',
alternate_phone: '',
notes: '',
type: 'person',
reported_date: 1478469976421,
},
name: 'Number three district',
external_id: '',
type: 'district_hospital',
}],
userContactDoc: {
_id: constants.USER_CONTACT_ID,
name: 'Jack',
date_of_birth: '',
phone: '+64274444444',
alternate_phone: '',
notes: '',
type: 'person',
reported_date: 1478469976421,
parent: {
_id: 'c49385b3594af7025ef097114104ef48',
reported_date: 1469578114543,
notes: '',
contact: {
_id: '3b3d50d275280d2568cd36281d00348b',
_id: constants.USER_CONTACT_ID,
name: 'Jack',
date_of_birth: '',
phone: '+64274444444',
Expand All @@ -19,33 +46,5 @@ module.exports = {
external_id: '',
type: 'district_hospital',
},
{
_id: '3b3d50d275280d2568cd36281d00348b',
name: 'Jack',
date_of_birth: '',
phone: '+64274444444',
alternate_phone: '',
notes: '',
type: 'person',
reported_date: 1478469976421,
parent: {
_id: 'c49385b3594af7025ef097114104ef48',
reported_date: 1469578114543,
notes: '',
contact: {
_id: '3b3d50d275280d2568cd36281d00348b',
name: 'Jack',
date_of_birth: '',
phone: '+64274444444',
alternate_phone: '',
notes: '',
type: 'person',
reported_date: 1478469976421,
},
name: 'Number three district',
external_id: '',
type: 'district_hospital',
},
},
],
},
};
4 changes: 2 additions & 2 deletions tests/page-objects/forms/delivery-report.po.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const selectRadioButton = value => {
};

module.exports = {
configureForm: (contactId, done) => {
utils.seedTestData(done, contactId, docs);
configureForm: (userContactDoc, done) => {
utils.seedTestData(done, userContactDoc, docs);
},

//patient page
Expand Down
4 changes: 2 additions & 2 deletions tests/page-objects/forms/family-survey-form.po.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const docs = [
];

module.exports = {
configureForm: (contactId, done) => {
utils.seedTestData(done, contactId, docs);
configureForm: (userContactDoc, done) => {
utils.seedTestData(done, userContactDoc, docs);
},

fillFamilySurvey: (pregnant, numberOfChildren) => {
Expand Down
4 changes: 2 additions & 2 deletions tests/page-objects/forms/photo-upload.po.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const docs = [
}];

module.exports = {
configureForm: (contactId, done) => {
utils.seedTestData(done, contactId, docs);
configureForm: (userContactDoc, done) => {
utils.seedTestData(done, userContactDoc, docs);
},

submit: () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/page-objects/forms/z-score.po.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ const clickAndGetValue = el => {
};

module.exports = {
configureForm: (contactId, done) => {
utils.seedTestData(done, contactId, docs);
configureForm: (userContactDoc, done) => {
utils.seedTestData(done, userContactDoc, docs);
},

load: () => {
Expand Down