Skip to content

Commit

Permalink
fix(#9389): update api/v1/person query param from personType to type (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuester authored and sugat009 committed Aug 29, 2024
1 parent a93dede commit beea361
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion api/src/controllers/person.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
8 changes: 4 additions & 4 deletions api/tests/mocha/controllers/person.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('Person Controller', () => {
beforeEach(() => {
req = {
query: {
personType,
type: personType,
cursor,
limit,
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion shared-libs/cht-datasource/src/remote/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export namespace v1 {
): Promise<Page<Person.v1.Person>> => {
const queryParams = {
'limit': limit.toString(),
'personType': personType.contactType,
'type': personType.contactType,
...(cursor ? { cursor } : {})
};
return getPeople(remoteContext)(queryParams);
Expand Down
2 changes: 1 addition & 1 deletion shared-libs/cht-datasource/test/remote/person.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('remote person', () => {
const personTypeQualifier = {contactType: personType};
const queryParam = {
limit: limit.toString(),
personType,
type: personType,
cursor,
};

Expand Down
6 changes: 3 additions & 3 deletions tests/integration/api/controllers/person.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit beea361

Please sign in to comment.