From beea361e40374a7882fcea93f8900d0df22b9e8a Mon Sep 17 00:00:00 2001 From: Joshua Kuestersteffen Date: Thu, 29 Aug 2024 00:01:31 -0500 Subject: [PATCH] fix(#9389): update api/v1/person query param from personType to type (#9390) --- api/src/controllers/person.js | 2 +- api/tests/mocha/controllers/person.spec.js | 8 ++++---- shared-libs/cht-datasource/src/remote/person.ts | 2 +- shared-libs/cht-datasource/test/remote/person.spec.ts | 2 +- tests/integration/api/controllers/person.spec.js | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/src/controllers/person.js b/api/src/controllers/person.js index 85d3127a4b3..55ea939fcd2 100644 --- a/api/src/controllers/person.js +++ b/api/src/controllers/person.js @@ -31,7 +31,7 @@ module.exports = { getAll: serverUtils.doOrError(async (req, res) => { await checkUserPermissions(req); - const personType = Qualifier.byContactType(req.query.personType); + const personType = Qualifier.byContactType(req.query.type); const limit = req.query.limit ? Number(req.query.limit) : req.query.limit; const docs = await getPageByType()( personType, req.query.cursor, limit ); diff --git a/api/tests/mocha/controllers/person.spec.js b/api/tests/mocha/controllers/person.spec.js index dae89c769fc..fd0eef10d35 100644 --- a/api/tests/mocha/controllers/person.spec.js +++ b/api/tests/mocha/controllers/person.spec.js @@ -169,7 +169,7 @@ describe('Person Controller', () => { beforeEach(() => { req = { query: { - personType, + type: personType, cursor, limit, } @@ -193,7 +193,7 @@ describe('Person Controller', () => { await controller.v1.getAll(req, res); expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true; - expect(qualifierByContactType.calledOnceWithExactly(req.query.personType)).to.be.true; + expect(qualifierByContactType.calledOnceWithExactly(req.query.type)).to.be.true; expect(dataContextBind.calledOnceWithExactly(Person.v1.getPage)).to.be.true; expect(personGetPageByType.calledOnceWithExactly(personTypeQualifier, cursor, limit)).to.be.true; expect(res.json.calledOnceWithExactly(people)).to.be.true; @@ -238,7 +238,7 @@ describe('Person Controller', () => { await controller.v1.getAll(req, res); expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true; - expect(qualifierByContactType.calledOnceWithExactly(req.query.personType)).to.be.true; + expect(qualifierByContactType.calledOnceWithExactly(req.query.type)).to.be.true; expect(dataContextBind.calledOnceWithExactly(Person.v1.getPage)).to.be.true; expect(personGetPageByType.calledOnceWithExactly(personTypeQualifier, cursor, limit)).to.be.true; expect(res.json.notCalled).to.be.true; @@ -254,7 +254,7 @@ describe('Person Controller', () => { await controller.v1.getAll(req, res); expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true; - expect(qualifierByContactType.calledOnceWithExactly(req.query.personType)).to.be.true; + expect(qualifierByContactType.calledOnceWithExactly(req.query.type)).to.be.true; expect(dataContextBind.calledOnceWithExactly(Person.v1.getPage)).to.be.true; expect(personGetPageByType.calledOnceWithExactly(personTypeQualifier, cursor, limit)).to.be.true; expect(res.json.notCalled).to.be.true; diff --git a/shared-libs/cht-datasource/src/remote/person.ts b/shared-libs/cht-datasource/src/remote/person.ts index 706ab17896a..0cb7919c35f 100644 --- a/shared-libs/cht-datasource/src/remote/person.ts +++ b/shared-libs/cht-datasource/src/remote/person.ts @@ -30,7 +30,7 @@ export namespace v1 { ): Promise> => { const queryParams = { 'limit': limit.toString(), - 'personType': personType.contactType, + 'type': personType.contactType, ...(cursor ? { cursor } : {}) }; return getPeople(remoteContext)(queryParams); diff --git a/shared-libs/cht-datasource/test/remote/person.spec.ts b/shared-libs/cht-datasource/test/remote/person.spec.ts index a4a91cbccc0..63ffe6e35a2 100644 --- a/shared-libs/cht-datasource/test/remote/person.spec.ts +++ b/shared-libs/cht-datasource/test/remote/person.spec.ts @@ -76,7 +76,7 @@ describe('remote person', () => { const personTypeQualifier = {contactType: personType}; const queryParam = { limit: limit.toString(), - personType, + type: personType, cursor, }; diff --git a/tests/integration/api/controllers/person.spec.js b/tests/integration/api/controllers/person.spec.js index 7a4686199da..ec61d3faaf5 100644 --- a/tests/integration/api/controllers/person.spec.js +++ b/tests/integration/api/controllers/person.spec.js @@ -188,7 +188,7 @@ describe('Person API', () => { it('throws 400 error when personType is invalid', async () => { const queryParams = { - 'personType': invalidContactType + type: invalidContactType }; const queryString = new URLSearchParams(queryParams).toString(); const opts = { @@ -201,7 +201,7 @@ describe('Person API', () => { it('throws 400 error when limit is invalid', async () => { const queryParams = { - personType, + type: personType, limit: -1 }; const queryString = new URLSearchParams(queryParams).toString(); @@ -215,7 +215,7 @@ describe('Person API', () => { it('throws 400 error when cursor is invalid', async () => { const queryParams = { - personType, + type: personType, cursor: '-1' }; const queryString = new URLSearchParams(queryParams).toString();