diff --git a/shared-libs/cht-datasource/test/local/contact.spec.ts b/shared-libs/cht-datasource/test/local/contact.spec.ts index bb6e13e1d0..1d8f6c1db3 100644 --- a/shared-libs/cht-datasource/test/local/contact.spec.ts +++ b/shared-libs/cht-datasource/test/local/contact.spec.ts @@ -740,63 +740,61 @@ describe('local contact', () => { } ); - it( - '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 = { - contactType, - freetext - }; - const docs = [ - { type: contactType, _id: '1' }, - { type: contactType, _id: '2' }, - { type: contactType, _id: '3' } - ]; - const fetchAndFilterResult = { - cursor: '8', - data: docs - }; - const expectedResult = { - cursor: '8', - data: ['1', '2', '3'] - }; - fetchAndFilterInner.resolves(fetchAndFilterResult); + it('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 = { + contactType, + freetext + }; + const docs = [ + { type: contactType, _id: '1' }, + { type: contactType, _id: '2' }, + { type: contactType, _id: '3' } + ]; + const fetchAndFilterResult = { + cursor: '8', + data: docs + }; + const expectedResult = { + cursor: '8', + data: ['1', '2', '3'] + }; + fetchAndFilterInner.resolves(fetchAndFilterResult); - const res = await Contact.v1.getPage(localContext)(qualifier, notNullCursor, limit); - const fetchAndFilterOuterFirstArg = fetchAndFilterOuter.firstCall.args[0] as (...args: unknown[]) => unknown; - const fetchAndFilterOuterString = fetchAndFilterOuterFirstArg.toString(); + const res = await Contact.v1.getPage(localContext)(qualifier, notNullCursor, limit); + const fetchAndFilterOuterFirstArg = fetchAndFilterOuter.firstCall.args[0] as (...args: unknown[]) => unknown; + const fetchAndFilterOuterString = fetchAndFilterOuterFirstArg.toString(); - expect(res).to.deep.equal(expectedResult); - expect(settingsGetAll.callCount).to.equal(1); - expect(getContactTypes.calledOnceWithExactly(settings)).to.be.true; - expect(queryDocsByKeyOuter.callCount).to.be.equal(3); - expect( - queryDocsByKeyOuter.getCall(0).args - ).to.deep.equal([localContext.medicDb, 'medic-client/contacts_by_type_freetext']); - expect( - queryDocsByKeyOuter.getCall(1).args - ).to.deep.equal([localContext.medicDb, 'medic-client/contacts_by_freetext']); - expect( - queryDocsByKeyOuter.getCall(2).args - ).to.deep.equal([localContext.medicDb, 'medic-client/contacts_by_type']); - expect(queryDocsByKeyInner.notCalled).to.be.true; - expect(queryDocsByRangeInner.notCalled).to.be.true; - expect(queryDocsByRangeOuter.callCount).to.be.equal(2); - expect( - queryDocsByRangeOuter.getCall(0).args - ).to.deep.equal([localContext.medicDb, 'medic-client/contacts_by_type_freetext']); - expect( - queryDocsByRangeOuter.getCall(1).args - ).to.deep.equal([localContext.medicDb, 'medic-client/contacts_by_freetext']); - expect(fetchAndFilterOuter.calledOnce).to.be.true; - expect(fetchAndFilterOuter.firstCall.args[0]).to.be.a('function'); - expect(fetchAndFilterOuterString.includes('getContactsByTypeFreetextRange(')).to.be.true; - expect(fetchAndFilterOuter.firstCall.args[1]).to.be.a('function'); - expect(fetchAndFilterOuter.firstCall.args[2]).to.be.equal(limit); - expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(notNullCursor))).to.be.true; - } - ); + expect(res).to.deep.equal(expectedResult); + expect(settingsGetAll.callCount).to.equal(1); + expect(getContactTypes.calledOnceWithExactly(settings)).to.be.true; + expect(queryDocsByKeyOuter.callCount).to.be.equal(3); + expect( + queryDocsByKeyOuter.getCall(0).args + ).to.deep.equal([localContext.medicDb, 'medic-client/contacts_by_type_freetext']); + expect( + queryDocsByKeyOuter.getCall(1).args + ).to.deep.equal([localContext.medicDb, 'medic-client/contacts_by_freetext']); + expect( + queryDocsByKeyOuter.getCall(2).args + ).to.deep.equal([localContext.medicDb, 'medic-client/contacts_by_type']); + expect(queryDocsByKeyInner.notCalled).to.be.true; + expect(queryDocsByRangeInner.notCalled).to.be.true; + expect(queryDocsByRangeOuter.callCount).to.be.equal(2); + expect( + queryDocsByRangeOuter.getCall(0).args + ).to.deep.equal([localContext.medicDb, 'medic-client/contacts_by_type_freetext']); + expect( + queryDocsByRangeOuter.getCall(1).args + ).to.deep.equal([localContext.medicDb, 'medic-client/contacts_by_freetext']); + expect(fetchAndFilterOuter.calledOnce).to.be.true; + expect(fetchAndFilterOuter.firstCall.args[0]).to.be.a('function'); + expect(fetchAndFilterOuterString.includes('getContactsByTypeFreetextRange(')).to.be.true; + expect(fetchAndFilterOuter.firstCall.args[1]).to.be.a('function'); + expect(fetchAndFilterOuter.firstCall.args[2]).to.be.equal(limit); + expect(fetchAndFilterInner.calledOnceWithExactly(limit, Number(notNullCursor))).to.be.true; + }); it('throws an error if contact type is invalid', async () => { await expect(Contact.v1.getPage(localContext)(invalidContactTypeQualifier, cursor, limit)).to.be.rejectedWith(