Skip to content

Commit

Permalink
change title of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sugat009 committed Dec 2, 2024
1 parent 30d058e commit 662598c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion shared-libs/cht-datasource/src/local/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 13 additions & 11 deletions shared-libs/cht-datasource/test/local/contact.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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' },
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down
24 changes: 20 additions & 4 deletions shared-libs/cht-datasource/test/local/report.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion shared-libs/cht-datasource/test/remote/contact.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion shared-libs/cht-datasource/test/remote/report.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 662598c

Please sign in to comment.