diff --git a/shared-libs/cht-datasource/src/local/report.ts b/shared-libs/cht-datasource/src/local/report.ts index be1762683c..49feaa16e9 100644 --- a/shared-libs/cht-datasource/src/local/report.ts +++ b/shared-libs/cht-datasource/src/local/report.ts @@ -16,7 +16,7 @@ export namespace v1 { logger.warn(`No report found for identifier [${uuid}].`); return false; } - } else if (doc.type !== 'data_record' && !doc.form) { + } else if (doc.type !== 'data_record' || !doc.form) { logger.warn(`Document [${doc._id}] is not a valid report.`); return false; } diff --git a/shared-libs/cht-datasource/test/local/contact.spec.ts b/shared-libs/cht-datasource/test/local/contact.spec.ts index d94bf0fb08..bb6e13e1d0 100644 --- a/shared-libs/cht-datasource/test/local/contact.spec.ts +++ b/shared-libs/cht-datasource/test/local/contact.spec.ts @@ -252,7 +252,7 @@ describe('local contact', () => { fetchAndFilterOuter = sinon.stub(LocalDoc, 'fetchAndFilter').returns(fetchAndFilterInner); }); - it('returns a page of contacts for contactType only qualifier', async () => { + it('returns a page of contact identifiers for contactType only qualifier', async () => { const qualifier = { contactType } as const; const docs = [ { type: contactType, _id: '1' }, @@ -303,7 +303,7 @@ describe('local contact', () => { expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(cursor))).to.be.true; }); - it('returns a page of contacts for freetext only qualifier with : delimiter', async () => { + it('returns a page of contact identifiers for freetext only qualifier with : delimiter', async () => { const freetext = 'has : delimiter'; const qualifier = { freetext @@ -357,7 +357,7 @@ describe('local contact', () => { expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(cursor))).to.be.true; }); - it('returns a page of contacts for freetext only qualifier without : delimiter', async () => { + it('returns a page of contact identifiers for freetext only qualifier without : delimiter', async () => { const freetext = 'does not have colon delimiter'; const qualifier = { freetext @@ -411,7 +411,7 @@ describe('local contact', () => { expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(cursor))).to.be.true; }); - it('returns a page of contacts for contactType and freetext qualifier with : delimiter', async () => { + it('returns a page of contact identifiers for contactType and freetext qualifier with : delimiter', async () => { const freetext = 'has : delimiter'; const qualifier = { contactType, @@ -466,7 +466,7 @@ describe('local contact', () => { expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(cursor))).to.be.true; }); - it('returns a page of contacts for contactType and freetext qualifier without delimiter', async () => { + it('returns a page of contact identifiers for contactType and freetext qualifier without delimiter', async () => { const freetext = 'does not have colon delimiter'; const qualifier = { contactType, @@ -521,7 +521,7 @@ describe('local contact', () => { expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(cursor))).to.be.true; }); - it('returns a page of contacts for contactType only qualifier for not-null cursor', async () => { + it('returns a page of contact identifiers for contactType only qualifier for not-null cursor', async () => { const qualifier = { contactType } as const; const docs = [ { type: contactType, _id: '1' }, @@ -572,7 +572,8 @@ describe('local contact', () => { expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(notNullCursor))).to.be.true; }); - it('returns a page of contacts for freetext only qualifier with : delimiter for not-null cursor', async () => { + it('returns a page of contact identifiers for freetext only' + + 'qualifier with : delimiter for not-null cursor', async () => { const freetext = 'has : delimiter'; const qualifier = { freetext @@ -626,7 +627,8 @@ describe('local contact', () => { expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(notNullCursor))).to.be.true; }); - it('returns a page of contacts for freetext only qualifier without : delimiter for not-null cursor', async () => { + it('returns a page of contact identifiers for freetext only qualifier' + + ' without : delimiter for not-null cursor', async () => { const freetext = 'does not have colon delimiter'; const qualifier = { freetext @@ -681,8 +683,8 @@ describe('local contact', () => { }); it( - 'returns a page of contacts for contactType and freetext qualifier with : delimiter for not-null cursor', - async () => { + 'returns a page of contact identifiers for contactType and freetext qualifier' + + 'with : delimiter for not-null cursor', async () => { const freetext = 'has : delimiter'; const qualifier = { contactType, @@ -739,7 +741,7 @@ describe('local contact', () => { ); it( - 'returns a page of contacts for contactType and freetext qualifier without delimiter for not-null cursor', + 'returns a page of contact identifiers for contactType and freetext qualifier without delimiter for not-null cursor', async () => { const freetext = 'does not have colon delimiter'; const qualifier = { diff --git a/shared-libs/cht-datasource/test/local/report.spec.ts b/shared-libs/cht-datasource/test/local/report.spec.ts index a5e22b6c08..350f9b7957 100644 --- a/shared-libs/cht-datasource/test/local/report.spec.ts +++ b/shared-libs/cht-datasource/test/local/report.spec.ts @@ -63,6 +63,20 @@ describe('local report', () => { expect(warn.calledOnceWithExactly(`Document [${doc._id}] is not a valid report.`)).to.be.true; }); + it('returns null if the identified doc does not have a form field', async () => { + const doc = { type: 'data_record', _id: '_id' }; + getDocByIdInner.resolves(doc); + settingsGetAll.returns(settings); + + // eslint-disable-next-line compat/compat + const result = await Report.v1.get(localContext)(identifier); + + expect(result).to.be.null; + expect(getDocByIdOuter.calledOnceWithExactly(localContext.medicDb)).to.be.true; + expect(getDocByIdInner.calledOnceWithExactly(identifier.uuid)).to.be.true; + expect(warn.calledOnceWithExactly(`Document [${doc._id}] is not a valid report.`)).to.be.true; + }); + it('returns null if the identified doc is not found', async () => { getDocByIdInner.resolves(null); @@ -98,7 +112,7 @@ describe('local report', () => { fetchAndFilterOuter = sinon.stub(LocalDoc, 'fetchAndFilter').returns(fetchAndFilterInner); }); - it('returns a page of reports for freetext only qualifier with : delimiter', async () => { + it('returns a page of report identifiers for freetext only qualifier with : delimiter', async () => { const freetext = 'has : delimiter'; const qualifier = { freetext @@ -142,7 +156,7 @@ describe('local report', () => { expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(cursor))).to.be.true; }); - it('returns a page of reports for freetext only qualifier without : delimiter', async () => { + it('returns a page of report identifiers for freetext only qualifier without : delimiter', async () => { const freetext = 'does not have colon delimiter'; const qualifier = { freetext @@ -186,7 +200,8 @@ describe('local report', () => { expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(cursor))).to.be.true; }); - it('returns a page of reports for freetext only qualifier with : delimiter for not-null cursor', async () => { + it('returns a page of report identifiers for freetext only qualifier' + + 'with : delimiter for not-null cursor', async () => { const freetext = 'has : delimiter'; const qualifier = { freetext @@ -230,7 +245,8 @@ describe('local report', () => { expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(notNullCursor))).to.be.true; }); - it('returns a page of reports for freetext only qualifier without : delimiter for not-null cursor', async () => { + it('returns a page of report identifiers for freetext only qualifier' + + 'without : delimiter for not-null cursor', async () => { const freetext = 'does not have colon delimiter'; const qualifier = { freetext diff --git a/shared-libs/cht-datasource/test/remote/contact.spec.ts b/shared-libs/cht-datasource/test/remote/contact.spec.ts index 697e71b547..29d865ad99 100644 --- a/shared-libs/cht-datasource/test/remote/contact.spec.ts +++ b/shared-libs/cht-datasource/test/remote/contact.spec.ts @@ -85,7 +85,7 @@ describe('remote contact', () => { cursor, }; - it('returns contacts', async () => { + it('returns array of contact identifiers', async () => { const doc = [{ type: 'person' }, {type: 'person'}]; const expectedResponse = { data: doc, cursor }; getResourcesInner.resolves(expectedResponse); diff --git a/shared-libs/cht-datasource/test/remote/report.spec.ts b/shared-libs/cht-datasource/test/remote/report.spec.ts index 18322b2873..6822eb9f28 100644 --- a/shared-libs/cht-datasource/test/remote/report.spec.ts +++ b/shared-libs/cht-datasource/test/remote/report.spec.ts @@ -61,7 +61,7 @@ describe('remote report', () => { cursor, }; - it('returns reports', async () => { + it('returns an array of report identifiers', async () => { const doc = [{ type: 'data_record', form: 'yes' }, {type: 'data_record', form: 'yes'}]; const expectedResponse = { data: doc, cursor }; getResourcesInner.resolves(expectedResponse);