diff --git a/api/src/controllers/contact.js b/api/src/controllers/contact.js index 5bd5d4b7b3..58d03e9a87 100644 --- a/api/src/controllers/contact.js +++ b/api/src/controllers/contact.js @@ -4,7 +4,7 @@ const ctx = require('../services/data-context'); const serverUtils = require('../server-utils'); const getContact = ({ with_lineage }) => ctx.bind(with_lineage === 'true' ? Contact.v1.getWithLineage : Contact.v1.get); -const getContactIds = () => ctx.bind(Contact.v1.getIdsPage); +const getContactIds = () => ctx.bind(Contact.v1.getUuidsPage); const checkUserPermissions = async (req) => { const userCtx = await auth.getUserCtx(req); diff --git a/api/src/controllers/report.js b/api/src/controllers/report.js index 22101a7e13..6ec9481323 100644 --- a/api/src/controllers/report.js +++ b/api/src/controllers/report.js @@ -4,7 +4,7 @@ const serverUtils = require('../server-utils'); const { Report, Qualifier } = require('@medic/cht-datasource'); const getReport = () => ctx.bind(Report.v1.get); -const getReportIds = () => ctx.bind(Report.v1.getIdsPage); +const getReportIds = () => ctx.bind(Report.v1.getUuidsPage); const checkUserPermissions = async (req) => { const userCtx = await auth.getUserCtx(req); diff --git a/shared-libs/cht-datasource/test/contact.spec.ts b/shared-libs/cht-datasource/test/contact.spec.ts index 32cec5c40c..72fe8dee3f 100644 --- a/shared-libs/cht-datasource/test/contact.spec.ts +++ b/shared-libs/cht-datasource/test/contact.spec.ts @@ -310,8 +310,9 @@ describe('contact', () => { .to.be.rejectedWith(`The limit must be a positive number: [${String(limitValue)}]`); expect(assertDataContext.calledOnceWithExactly(dataContext)).to.be.true; - expect(adapt.calledOnceWithExactly(dataContext, Local.Contact.v1.getUuidsPage, Remote.Contact.v1.getUuidsPage)) - .to.be.true; + expect( + adapt.calledOnceWithExactly(dataContext, Local.Contact.v1.getUuidsPage, Remote.Contact.v1.getUuidsPage) + ).to.be.true; expect(isContactTypeQualifier.notCalled).to.be.true; expect(isFreetextQualifier.notCalled).to.be.true; expect(getIdsPage.notCalled).to.be.true; @@ -332,8 +333,9 @@ describe('contact', () => { .to.be.rejectedWith(`Invalid cursor token: [${String(skipValue)}]`); expect(assertDataContext.calledOnceWithExactly(dataContext)).to.be.true; - expect(adapt.calledOnceWithExactly(dataContext, Local.Contact.v1.getUuidsPage, Remote.Contact.v1.getUuidsPage)) - .to.be.true; + expect( + adapt.calledOnceWithExactly(dataContext, Local.Contact.v1.getUuidsPage, Remote.Contact.v1.getUuidsPage) + ).to.be.true; expect(isContactTypeQualifier.notCalled).to.be.true; expect(isFreetextQualifier.notCalled).to.be.true; expect(getIdsPage.notCalled).to.be.true; diff --git a/shared-libs/cht-datasource/test/local/contact.spec.ts b/shared-libs/cht-datasource/test/local/contact.spec.ts index bda9f3222a..83cf546440 100644 --- a/shared-libs/cht-datasource/test/local/contact.spec.ts +++ b/shared-libs/cht-datasource/test/local/contact.spec.ts @@ -798,7 +798,9 @@ describe('local contact', () => { }); it('throws an error if contact type is invalid', async () => { - await expect(Contact.v1.getUuidsPage(localContext)(invalidContactTypeQualifier, cursor, limit)).to.be.rejectedWith( + await expect( + Contact.v1.getUuidsPage(localContext)(invalidContactTypeQualifier, cursor, limit) + ).to.be.rejectedWith( `Invalid contact type [${invalidContactTypeQualifier.contactType}].` ); diff --git a/shared-libs/cht-datasource/test/report.spec.ts b/shared-libs/cht-datasource/test/report.spec.ts index 9a868791c7..ef2cdfad78 100644 --- a/shared-libs/cht-datasource/test/report.spec.ts +++ b/shared-libs/cht-datasource/test/report.spec.ts @@ -95,7 +95,9 @@ describe('report', () => { expect(result).to.equal(pageData); expect(assertDataContext.calledOnceWithExactly(dataContext)).to.be.true; - expect(adapt.calledOnceWithExactly(dataContext, Local.Report.v1.getUuidsPage, Remote.Report.v1.getUuidsPage)).to.be.true; + expect( + adapt.calledOnceWithExactly(dataContext, Local.Report.v1.getUuidsPage, Remote.Report.v1.getUuidsPage) + ).to.be.true; expect(getIdsPage.calledOnceWithExactly(freetextQualifier, null, limit)).to.be.true; expect(isFreetextQualifier.calledOnceWithExactly(freetextQualifier)).to.be.true; }); @@ -108,7 +110,9 @@ describe('report', () => { expect(result).to.equal(pageData); expect(assertDataContext.calledOnceWithExactly(dataContext)).to.be.true; - expect(adapt.calledOnceWithExactly(dataContext, Local.Report.v1.getUuidsPage, Remote.Report.v1.getUuidsPage)).to.be.true; + expect( + adapt.calledOnceWithExactly(dataContext, Local.Report.v1.getUuidsPage, Remote.Report.v1.getUuidsPage) + ).to.be.true; expect(getIdsPage.calledOnceWithExactly(freetextQualifier, cursor, limit)).to.be.true; expect(isFreetextQualifier.calledOnceWithExactly(freetextQualifier)).to.be.true; }); @@ -122,7 +126,9 @@ describe('report', () => { expect(result).to.equal(pageData); expect(assertDataContext.calledOnceWithExactly(dataContext)).to.be.true; - expect(adapt.calledOnceWithExactly(dataContext, Local.Report.v1.getUuidsPage, Remote.Report.v1.getUuidsPage)).to.be.true; + expect( + adapt.calledOnceWithExactly(dataContext, Local.Report.v1.getUuidsPage, Remote.Report.v1.getUuidsPage) + ).to.be.true; expect(getIdsPage.calledOnceWithExactly(freetextQualifier, cursor, limit)).to.be.true; expect(isFreetextQualifier.calledOnceWithExactly(freetextQualifier)).to.be.true; }); @@ -146,7 +152,9 @@ describe('report', () => { .to.be.rejectedWith(`Invalid freetext [${JSON.stringify(invalidFreetextQualifier)}].`); expect(assertDataContext.calledOnceWithExactly(dataContext)).to.be.true; - expect(adapt.calledOnceWithExactly(dataContext, Local.Report.v1.getUuidsPage, Remote.Report.v1.getUuidsPage)).to.be.true; + expect( + adapt.calledOnceWithExactly(dataContext, Local.Report.v1.getUuidsPage, Remote.Report.v1.getUuidsPage) + ).to.be.true; expect(isFreetextQualifier.calledOnceWithExactly(invalidFreetextQualifier)).to.be.true; expect(getIdsPage.notCalled).to.be.true; }); diff --git a/tests/integration/api/controllers/contact.spec.js b/tests/integration/api/controllers/contact.spec.js index 1228b60074..4b407a4f9b 100644 --- a/tests/integration/api/controllers/contact.spec.js +++ b/tests/integration/api/controllers/contact.spec.js @@ -218,13 +218,13 @@ describe('Contact API', () => { }); }); - describe('GET /api/v1/contact/id', async () => { + describe('GET /api/v1/contact/uuid', async () => { const fourLimit = 4; const twoLimit = 2; const invalidContactType = 'invalidPerson'; const freetext = 'contact'; const placeFreetext = 'clinic'; - const endpoint = '/api/v1/contact/id'; + const endpoint = '/api/v1/contact/uuid'; it('returns a page of people type contact ids for no limit and cursor passed', async () => { const queryParams = { @@ -489,7 +489,7 @@ describe('Contact API', () => { it(`throws error when user does not have can_view_contacts permission`, async () => { const opts = { - path: `/api/v1/contact/id`, + path: endpoint, auth: { username: userNoPerms.username, password: userNoPerms.password }, }; await expect(utils.request(opts)).to.be.rejectedWith('403 - {"code":403,"error":"Insufficient privileges"}'); @@ -497,7 +497,7 @@ describe('Contact API', () => { it(`throws error when user is not an online user`, async () => { const opts = { - path: `/api/v1/contact/id`, + path: endpoint, auth: { username: offlineUser.username, password: offlineUser.password }, }; await expect(utils.request(opts)).to.be.rejectedWith('403 - {"code":403,"error":"Insufficient privileges"}'); @@ -509,7 +509,7 @@ describe('Contact API', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/contact/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) @@ -523,7 +523,7 @@ describe('Contact API', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/contact/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) @@ -537,7 +537,7 @@ describe('Contact API', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/contact/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) diff --git a/tests/integration/api/controllers/report.spec.js b/tests/integration/api/controllers/report.spec.js index d5db512da1..602384628c 100644 --- a/tests/integration/api/controllers/report.spec.js +++ b/tests/integration/api/controllers/report.spec.js @@ -122,10 +122,10 @@ describe('Report API', () => { }); }); - describe('GET /api/v1/report/id', async () => { + describe('GET /api/v1/report/uuid', async () => { const freetext = 'report'; const limit = 4; - const endpoint = '/api/v1/report/id'; + const endpoint = '/api/v1/report/uuid'; it('returns a page of report ids for no limit and cursor passed', async () => { const queryParams = { @@ -177,14 +177,14 @@ describe('Report API', () => { it(`throws error when user does not have can_view_reports permission`, async () => { const opts = { - path: `/api/v1/report/id`, auth: {username: userNoPerms.username, password: userNoPerms.password}, + path: endpoint, auth: {username: userNoPerms.username, password: userNoPerms.password}, }; await expect(utils.request(opts)).to.be.rejectedWith('403 - {"code":403,"error":"Insufficient privileges"}'); }); it(`throws error when user is not an online user`, async () => { const opts = { - path: `/api/v1/report/id`, auth: {username: offlineUser.username, password: offlineUser.password}, + path: endpoint, auth: {username: offlineUser.username, password: offlineUser.password}, }; await expect(utils.request(opts)).to.be.rejectedWith('403 - {"code":403,"error":"Insufficient privileges"}'); }); @@ -195,7 +195,7 @@ describe('Report API', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/report/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) @@ -208,7 +208,7 @@ describe('Report API', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/report/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) @@ -221,7 +221,7 @@ describe('Report API', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/report/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) diff --git a/tests/integration/shared-libs/cht-datasource/contact.spec.js b/tests/integration/shared-libs/cht-datasource/contact.spec.js index dfc0ee3148..0be9f3e480 100644 --- a/tests/integration/shared-libs/cht-datasource/contact.spec.js +++ b/tests/integration/shared-libs/cht-datasource/contact.spec.js @@ -148,8 +148,8 @@ describe('Contact', () => { }); }); - describe('getIdsPage', async () => { - const getIdsPage = Contact.v1.getIdsPage(dataContext); + describe('getUuidsPage', async () => { + const getIdsPage = Contact.v1.getUuidsPage(dataContext); const fourLimit = 4; const twoLimit = 2; const stringifiedLimit = '7'; @@ -157,6 +157,7 @@ describe('Contact', () => { const invalidContactType = 'invalidPerson'; const freetext = 'contact'; const placeFreetext = 'clinic'; + const endpoint = '/api/v1/contact/uuid'; it('returns a page of people type contact ids for no limit and cursor passed', async () => { const responsePage = await getIdsPage(Qualifier.byContactType(personType)); @@ -306,14 +307,14 @@ describe('Contact', () => { it(`throws error when user does not have can_view_contacts permission`, async () => { const opts = { - path: `/api/v1/contact/id`, auth: {username: userNoPerms.username, password: userNoPerms.password}, + path: endpoint, auth: {username: userNoPerms.username, password: userNoPerms.password}, }; await expect(utils.request(opts)).to.be.rejectedWith('403 - {"code":403,"error":"Insufficient privileges"}'); }); it(`throws error when user is not an online user`, async () => { const opts = { - path: `/api/v1/contact/id`, auth: {username: offlineUser.username, password: offlineUser.password}, + path: endpoint, auth: {username: offlineUser.username, password: offlineUser.password}, }; await expect(utils.request(opts)).to.be.rejectedWith('403 - {"code":403,"error":"Insufficient privileges"}'); }); @@ -324,7 +325,7 @@ describe('Contact', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/contact/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) @@ -337,7 +338,7 @@ describe('Contact', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/contact/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) @@ -350,7 +351,7 @@ describe('Contact', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/contact/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) @@ -358,7 +359,7 @@ describe('Contact', () => { }); }); - describe('Contact.v1.getIds', async () => { + describe('Contact.v1.getUuids', async () => { it('fetches all data by iterating through generator', async () => { const docs = []; diff --git a/tests/integration/shared-libs/cht-datasource/report.spec.js b/tests/integration/shared-libs/cht-datasource/report.spec.js index a11d48c90b..d806047b75 100644 --- a/tests/integration/shared-libs/cht-datasource/report.spec.js +++ b/tests/integration/shared-libs/cht-datasource/report.spec.js @@ -107,19 +107,20 @@ describe('Report', () => { ].forEach(([ description, user ]) => { it(`throws error when user ${description}`, async () => { const opts = { - path: `/api/v1/report/${patient._id}`, auth: {username: user.username, password: user.password}, + path: `/api/v1/report/${report0._id}`, auth: {username: user.username, password: user.password}, }; await expect(utils.request(opts)).to.be.rejectedWith('403 - {"code":403,"error":"Insufficient privileges"}'); }); }); }); - describe('getIdsPage', async () => { - const getReport = Report.v1.getIdsPage(dataContext); + describe('getUuidsPage', async () => { + const getReport = Report.v1.getUuidsPage(dataContext); const freetext = 'report'; const limit = 4; const stringifiedLimit = '6'; const cursor = null; + const endpoint = '/api/v1/report/uuid'; it('returns a page of report ids for no limit and cursor passed', async () => { const responsePage = await getReport(Qualifier.byFreetext(freetext)); @@ -154,14 +155,14 @@ describe('Report', () => { it(`throws error when user does not have can_view_reports permission`, async () => { const opts = { - path: `/api/v1/report/id`, auth: {username: userNoPerms.username, password: userNoPerms.password}, + path: endpoint, auth: {username: userNoPerms.username, password: userNoPerms.password}, }; await expect(utils.request(opts)).to.be.rejectedWith('403 - {"code":403,"error":"Insufficient privileges"}'); }); it(`throws error when user is not an online user`, async () => { const opts = { - path: `/api/v1/report/id`, auth: {username: offlineUser.username, password: offlineUser.password}, + path: endpoint, auth: {username: offlineUser.username, password: offlineUser.password}, }; await expect(utils.request(opts)).to.be.rejectedWith('403 - {"code":403,"error":"Insufficient privileges"}'); }); @@ -172,7 +173,7 @@ describe('Report', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/report/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) @@ -185,7 +186,7 @@ describe('Report', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/report/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) @@ -198,7 +199,7 @@ describe('Report', () => { }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { - path: `/api/v1/report/id?${queryString}`, + path: `${endpoint}?${queryString}`, }; await expect(utils.request(opts)) @@ -206,7 +207,7 @@ describe('Report', () => { }); }); - describe('getIds', async () => { + describe('getUuids', async () => { it('fetches all data by iterating through generator', async () => { const freetext = 'report'; const docs = [];