Skip to content

Commit

Permalink
fix api unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sugat009 committed Dec 31, 2024
1 parent 22da4b9 commit 4a0d2bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
64 changes: 32 additions & 32 deletions api/tests/mocha/controllers/contact.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ describe('Contact Controller', () => {
});
});

describe('getIds', () => {
let contactGetIdsPage;
describe('getUuids', () => {
let contactGetUuidsPage;
let qualifierByContactType;
let qualifierByFreetext;
const contactType = 'person';
Expand All @@ -172,10 +172,10 @@ describe('Contact Controller', () => {
const contacts = Array.from({ length: 3 }, () => ({ ...contact }));

beforeEach(() => {
contactGetIdsPage = sinon.stub();
contactGetUuidsPage = sinon.stub();
qualifierByContactType = sinon.stub(Qualifier, 'byContactType');
qualifierByFreetext = sinon.stub(Qualifier, 'byFreetext');
dataContextBind.withArgs(Contact.v1.getIdsPage).returns(contactGetIdsPage);
dataContextBind.withArgs(Contact.v1.getUuidsPage).returns(contactGetUuidsPage);
qualifierByContactType.returns(contactTypeOnlyQualifier);
qualifierByFreetext.returns(freetextOnlyQualifier);
});
Expand All @@ -195,15 +195,15 @@ describe('Contact Controller', () => {
};
isOnlineOnly.returns(true);
hasAllPermissions.returns(true);
contactGetIdsPage.resolves(contacts);
contactGetUuidsPage.resolves(contacts);

await controller.v1.getUuids(req, res);

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true;
expect(qualifierByContactType.calledOnceWithExactly(req.query.type)).to.be.true;
expect(qualifierByFreetext.notCalled).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getIdsPage)).to.be.true;
expect(contactGetIdsPage.calledOnceWithExactly(contactTypeOnlyQualifier, cursor, limit)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getUuidsPage)).to.be.true;
expect(contactGetUuidsPage.calledOnceWithExactly(contactTypeOnlyQualifier, cursor, limit)).to.be.true;
expect(res.json.calledOnceWithExactly(contacts)).to.be.true;
expect(serverUtilsError.notCalled).to.be.true;
});
Expand All @@ -218,15 +218,15 @@ describe('Contact Controller', () => {
};
isOnlineOnly.returns(true);
hasAllPermissions.returns(true);
contactGetIdsPage.resolves(contacts);
contactGetUuidsPage.resolves(contacts);

await controller.v1.getUuids(req, res);

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true;
expect(qualifierByContactType.notCalled).to.be.true;
expect(qualifierByFreetext.calledOnceWithExactly(req.query.freetext)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getIdsPage)).to.be.true;
expect(contactGetIdsPage.calledOnceWithExactly(freetextOnlyQualifier, cursor, limit)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getUuidsPage)).to.be.true;
expect(contactGetUuidsPage.calledOnceWithExactly(freetextOnlyQualifier, cursor, limit)).to.be.true;
expect(res.json.calledOnceWithExactly(contacts)).to.be.true;
expect(serverUtilsError.notCalled).to.be.true;
});
Expand All @@ -242,15 +242,15 @@ describe('Contact Controller', () => {
};
isOnlineOnly.returns(true);
hasAllPermissions.returns(true);
contactGetIdsPage.resolves(contacts);
contactGetUuidsPage.resolves(contacts);

await controller.v1.getUuids(req, res);

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true;
expect(qualifierByContactType.calledOnceWithExactly(req.query.type)).to.be.true;
expect(qualifierByFreetext.calledOnceWithExactly(req.query.freetext)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getIdsPage)).to.be.true;
expect(contactGetIdsPage.calledOnceWithExactly(bothQualifier, cursor, limit)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getUuidsPage)).to.be.true;
expect(contactGetUuidsPage.calledOnceWithExactly(bothQualifier, cursor, limit)).to.be.true;
expect(res.json.calledOnceWithExactly(contacts)).to.be.true;
expect(serverUtilsError.notCalled).to.be.true;
});
Expand All @@ -265,15 +265,15 @@ describe('Contact Controller', () => {
};
isOnlineOnly.returns(true);
hasAllPermissions.returns(true);
contactGetIdsPage.resolves(contacts);
contactGetUuidsPage.resolves(contacts);

await controller.v1.getUuids(req, res);

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true;
expect(qualifierByContactType.calledOnceWithExactly(req.query.type)).to.be.true;
expect(qualifierByFreetext.calledOnceWithExactly(req.query.freetext)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getIdsPage)).to.be.true;
expect(contactGetIdsPage.calledOnceWithExactly(bothQualifier, cursor, undefined)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getUuidsPage)).to.be.true;
expect(contactGetUuidsPage.calledOnceWithExactly(bothQualifier, cursor, undefined)).to.be.true;
expect(res.json.calledOnceWithExactly(contacts)).to.be.true;
expect(serverUtilsError.notCalled).to.be.true;
});
Expand All @@ -290,15 +290,15 @@ describe('Contact Controller', () => {
const err = new InvalidArgumentError(`The limit must be a positive number: [NaN].`);
isOnlineOnly.returns(true);
hasAllPermissions.returns(true);
contactGetIdsPage.throws(err);
contactGetUuidsPage.throws(err);

await controller.v1.getUuids(req, res);

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true;
expect(qualifierByContactType.calledOnceWithExactly(req.query.type)).to.be.true;
expect(qualifierByFreetext.calledOnceWithExactly(req.query.freetext)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getIdsPage)).to.be.true;
expect(contactGetIdsPage.calledOnceWithExactly(bothQualifier, cursor, null)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getUuidsPage)).to.be.true;
expect(contactGetUuidsPage.calledOnceWithExactly(bothQualifier, cursor, null)).to.be.true;
expect(res.json.notCalled).to.be.true;
expect(serverUtilsError.calledOnceWithExactly(err, req, res)).to.be.true;
});
Expand All @@ -322,7 +322,7 @@ describe('Contact Controller', () => {
expect(dataContextBind.notCalled).to.be.true;
expect(qualifierByContactType.notCalled).to.be.true;
expect(qualifierByFreetext.notCalled).to.be.true;
expect(contactGetIdsPage.notCalled).to.be.true;
expect(contactGetUuidsPage.notCalled).to.be.true;
expect(res.json.notCalled).to.be.true;
expect(serverUtilsError.calledOnceWithExactly(error, req, res)).to.be.true;
});
Expand All @@ -345,7 +345,7 @@ describe('Contact Controller', () => {
expect(dataContextBind.notCalled).to.be.true;
expect(qualifierByContactType.notCalled).to.be.true;
expect(qualifierByFreetext.notCalled).to.be.true;
expect(contactGetIdsPage.notCalled).to.be.true;
expect(contactGetUuidsPage.notCalled).to.be.true;
expect(res.json.notCalled).to.be.true;
expect(serverUtilsError.calledOnceWithExactly(error, req, res)).to.be.true;
});
Expand All @@ -361,15 +361,15 @@ describe('Contact Controller', () => {
const err = new InvalidArgumentError(`Invalid contact type: [${invalidContactType}]`);
isOnlineOnly.returns(true);
hasAllPermissions.returns(true);
contactGetIdsPage.throws(err);
contactGetUuidsPage.throws(err);

await controller.v1.getUuids(req, res);

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true;
expect(qualifierByContactType.calledOnceWithExactly(req.query.type)).to.be.true;
expect(qualifierByFreetext.notCalled).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getIdsPage)).to.be.true;
expect(contactGetIdsPage.calledOnceWithExactly(contactTypeOnlyQualifier, cursor, limit)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getUuidsPage)).to.be.true;
expect(contactGetUuidsPage.calledOnceWithExactly(contactTypeOnlyQualifier, cursor, limit)).to.be.true;
expect(res.json.notCalled).to.be.true;
expect(serverUtilsError.calledOnceWithExactly(err, req, res)).to.be.true;
});
Expand All @@ -385,15 +385,15 @@ describe('Contact Controller', () => {
const err = new InvalidArgumentError(`Invalid freetext: [${invalidFreetext}]`);
isOnlineOnly.returns(true);
hasAllPermissions.returns(true);
contactGetIdsPage.throws(err);
contactGetUuidsPage.throws(err);

await controller.v1.getUuids(req, res);

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true;
expect(qualifierByContactType.notCalled).to.be.true;
expect(qualifierByFreetext.calledOnceWithExactly(req.query.freetext)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getIdsPage)).to.be.true;
expect(contactGetIdsPage.calledOnceWithExactly(freetextOnlyQualifier, cursor, limit)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getUuidsPage)).to.be.true;
expect(contactGetUuidsPage.calledOnceWithExactly(freetextOnlyQualifier, cursor, limit)).to.be.true;
expect(res.json.notCalled).to.be.true;
expect(serverUtilsError.calledOnceWithExactly(err, req, res)).to.be.true;
});
Expand All @@ -408,15 +408,15 @@ describe('Contact Controller', () => {
const err = { status: 400, message: 'Either query param freetext or type is required' };
isOnlineOnly.returns(true);
hasAllPermissions.returns(true);
contactGetIdsPage.throws(err);
contactGetUuidsPage.throws(err);

await controller.v1.getUuids(req, res);

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true;
expect(qualifierByContactType.notCalled).to.be.true;
expect(qualifierByFreetext.notCalled).to.be.true;
expect(dataContextBind.notCalled).to.be.true;
expect(contactGetIdsPage.notCalled).to.be.true;
expect(contactGetUuidsPage.notCalled).to.be.true;
expect(res.json.notCalled).to.be.true;
expect(serverUtilsError.calledOnceWithExactly(err, req, res)).to.be.true;
});
Expand All @@ -433,15 +433,15 @@ describe('Contact Controller', () => {
const err = new Error('error');
isOnlineOnly.returns(true);
hasAllPermissions.returns(true);
contactGetIdsPage.throws(err);
contactGetUuidsPage.throws(err);

await controller.v1.getUuids(req, res);

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_contacts')).to.be.true;
expect(qualifierByContactType.calledOnceWithExactly(req.query.type)).to.be.true;
expect(qualifierByFreetext.calledOnceWithExactly(req.query.freetext)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getIdsPage)).to.be.true;
expect(contactGetIdsPage.calledOnceWithExactly(bothQualifier, cursor, limit)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Contact.v1.getUuidsPage)).to.be.true;
expect(contactGetUuidsPage.calledOnceWithExactly(bothQualifier, cursor, limit)).to.be.true;
expect(res.json.notCalled).to.be.true;
expect(serverUtilsError.calledOnceWithExactly(err, req, res)).to.be.true;
});
Expand Down
14 changes: 7 additions & 7 deletions api/tests/mocha/controllers/report.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('Report Controller Tests', () => {
});
});

describe('getIds', () => {
describe('getUuids', () => {
let reportGetIdsPage;
let qualifierByFreetext;
const freetext = 'report';
Expand All @@ -132,7 +132,7 @@ describe('Report Controller Tests', () => {
};
reportGetIdsPage = sinon.stub();
qualifierByFreetext = sinon.stub(Qualifier, 'byFreetext');
dataContextBind.withArgs(Report.v1.getIdsPage).returns(reportGetIdsPage);
dataContextBind.withArgs(Report.v1.getUuidsPage).returns(reportGetIdsPage);
qualifierByFreetext.returns(freetextOnlyQualifier);
});

Expand All @@ -157,7 +157,7 @@ describe('Report Controller Tests', () => {

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_reports')).to.be.true;
expect(qualifierByFreetext.calledOnceWithExactly(req.query.freetext)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Report.v1.getIdsPage)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Report.v1.getUuidsPage)).to.be.true;
expect(reportGetIdsPage.calledOnceWithExactly(freetextOnlyQualifier, cursor, limit)).to.be.true;
expect(res.json.calledOnceWithExactly(reports)).to.be.true;
expect(serverUtilsError.notCalled).to.be.true;
Expand All @@ -178,7 +178,7 @@ describe('Report Controller Tests', () => {

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_reports')).to.be.true;
expect(qualifierByFreetext.calledOnceWithExactly(req.query.freetext)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Report.v1.getIdsPage)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Report.v1.getUuidsPage)).to.be.true;
expect(reportGetIdsPage.calledOnceWithExactly(freetextOnlyQualifier, cursor, undefined)).to.be.true;
expect(res.json.calledOnceWithExactly(reports)).to.be.true;
expect(serverUtilsError.notCalled).to.be.true;
Expand All @@ -201,7 +201,7 @@ describe('Report Controller Tests', () => {

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_reports')).to.be.true;
expect(qualifierByFreetext.calledOnceWithExactly(req.query.freetext)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Report.v1.getIdsPage)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Report.v1.getUuidsPage)).to.be.true;
expect(reportGetIdsPage.calledOnceWithExactly(freetextOnlyQualifier, cursor, null)).to.be.true;
expect(res.json.notCalled).to.be.true;
expect(serverUtilsError.calledOnceWithExactly(err, req, res)).to.be.true;
Expand Down Expand Up @@ -267,7 +267,7 @@ describe('Report Controller Tests', () => {

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_reports')).to.be.true;
expect(qualifierByFreetext.calledOnceWithExactly(req.query.freetext)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Report.v1.getIdsPage)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Report.v1.getUuidsPage)).to.be.true;
expect(reportGetIdsPage.calledOnceWithExactly(freetextOnlyQualifier, cursor, limit)).to.be.true;
expect(res.json.notCalled).to.be.true;
expect(serverUtilsError.calledOnceWithExactly(err, req, res)).to.be.true;
Expand All @@ -290,7 +290,7 @@ describe('Report Controller Tests', () => {

expect(hasAllPermissions.calledOnceWithExactly(userCtx, 'can_view_reports')).to.be.true;
expect(qualifierByFreetext.calledOnceWithExactly(req.query.freetext)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Report.v1.getIdsPage)).to.be.true;
expect(dataContextBind.calledOnceWithExactly(Report.v1.getUuidsPage)).to.be.true;
expect(reportGetIdsPage.calledOnceWithExactly(freetextOnlyQualifier, cursor, limit)).to.be.true;
expect(res.json.notCalled).to.be.true;
expect(serverUtilsError.calledOnceWithExactly(err, req, res)).to.be.true;
Expand Down

0 comments on commit 4a0d2bb

Please sign in to comment.