Skip to content

Commit

Permalink
Move Person.v1.getAll integration tests to tests/integration/api/cont…
Browse files Browse the repository at this point in the history
…rollers/person.spec.js

and address PR comments
  • Loading branch information
sugat009 committed Aug 22, 2024
1 parent 047ff66 commit d8bb7fb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 76 deletions.
20 changes: 20 additions & 0 deletions shared-libs/cht-datasource/test/local/person.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,26 @@ describe('local person', () => {
expect(isPerson.notCalled).to.be.true;
});

[
{},
'',
'-1',
undefined,
false
].forEach((invalidSkip ) => {
it(`throws an error if cursor is invalid: ${String(invalidSkip)}`, async () => {
await expect(Person.v1.getPage(localContext)(invalidPersonTypeQualifier, invalidSkip as string, limit))
.to.be.rejectedWith(`Invalid contact type [${invalidPersonTypeQualifier.contactType}]`);

expect(settingsGetAll.calledOnce).to.be.true;
expect(getPersonTypes.calledOnceWithExactly(settings)).to.be.true;
expect(queryDocsByKeyOuter.calledOnceWithExactly(localContext.medicDb, 'medic-client/contacts_by_type'))
.to.be.true;
expect(queryDocsByKeyInner.notCalled).to.be.true;
expect(isPerson.notCalled).to.be.true;
});
});

it('returns empty array if people does not exist', async () => {
queryDocsByKeyInner.resolves([]);
const expectedResult = {
Expand Down
84 changes: 51 additions & 33 deletions tests/integration/api/controllers/person.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,42 @@ describe('Person API', () => {
}));
const allDocItems = [contact0, contact1, contact2, place0, place1, place2, patient];
const dataContext = getRemoteDataContext(utils.getOrigin());
const personType = 'person';
const e2eTestUser = {
'_id': 'e2e_contact_test_id',
'type': 'person',
'type': personType,
};
const onlineUserPlaceHierarchy = {
parent: {
_id: place1._id,
parent: {
_id: place2._id,
}
}
};
const offlineUserPlaceHierarchy = {
parent: {
_id: place0._id,
...onlineUserPlaceHierarchy
}
};
const expectedPeople = [
contact0,
contact1,
contact2,
patient,
e2eTestUser,
{
type: personType,
...userNoPerms.contact,
...onlineUserPlaceHierarchy
},
{
type: personType,
...offlineUser.contact,
...offlineUserPlaceHierarchy
}
];

before(async () => {
await utils.saveDocs(allDocItems);
Expand Down Expand Up @@ -114,39 +146,7 @@ describe('Person API', () => {
const getPage = Person.v1.getPage(dataContext);
const limit = 4;
const cursor = null;
const personType = 'person';
const invalidContactType = 'invalidPerson';
const onlineUserPlaceHierarchy = {
parent: {
_id: place1._id,
parent: {
_id: place2._id,
}
}
};
const offlineUserPlaceHierarchy = {
parent: {
_id: place0._id,
...onlineUserPlaceHierarchy
}
};
const expectedPeople = [
contact0,
contact1,
contact2,
patient,
e2eTestUser,
{
type: personType,
...userNoPerms.contact,
...onlineUserPlaceHierarchy
},
{
type: personType,
...offlineUser.contact,
...offlineUserPlaceHierarchy
}
];

it('returns a page of people for no limit and cursor passed', async () => {
const responsePage = await getPage(Qualifier.byContactType(personType));
Expand All @@ -164,6 +164,8 @@ describe('Person API', () => {
const allPeople = [...firstPage.data, ...secondPage.data];

expect(allPeople).excludingEvery(['_rev', 'reported_date']).to.deep.equalInAnyOrder(expectedPeople);
expect(firstPage.data.length).to.be.equal(4);
expect(secondPage.data.length).to.be.equal(3);
expect(firstPage.cursor).to.be.equal('4');
expect(secondPage.cursor).to.be.equal(null);
});
Expand Down Expand Up @@ -227,4 +229,20 @@ describe('Person API', () => {
);
});
});

describe('Person.v1.getAll', async () => {
const personType = 'person';

it('fetches all data by iterating through generator', async () => {
const docs = [];

const generator = Person.v1.getAll(dataContext)(Qualifier.byContactType(personType));

for await (const doc of generator) {
docs.push(doc);
}

expect(docs).excluding(['_rev', 'reported_date']).to.deep.equalInAnyOrder(expectedPeople);
});
});
});
43 changes: 0 additions & 43 deletions tests/integration/cht-datasource/person.spec.js

This file was deleted.

0 comments on commit d8bb7fb

Please sign in to comment.