Skip to content

Commit

Permalink
COM-3666: change naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysseferreira committed Mar 13, 2024
1 parent ad28984 commit 277e4cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/routes/preHandlers/companies.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ exports.authorizeCompanyUpdate = async (req) => {

if (!billingRepresentative) throw Boom.notFound();

const isClientAdminInGoodCompany = get(billingRepresentative, 'role.client.name') === CLIENT_ADMIN &&
const isClientAdminOfUpdatedCompany = get(billingRepresentative, 'role.client.name') === CLIENT_ADMIN &&
UtilsHelper.areObjectIdsEquals(billingRepresentative.company, updatedCompanyId);

if (!isClientAdminInGoodCompany) {
if (!isClientAdminOfUpdatedCompany) {
const companyHoldingExists = await CompanyHolding
.countDocuments({ company: updatedCompanyId, holding: billingRepresentative.holding });
const isHoldingAdminInGoodHolding = get(billingRepresentative, 'role.holding.name') === HOLDING_ADMIN &&
const isHoldingAdminOfUpdatedCompanyHolding = get(billingRepresentative, 'role.holding.name') === HOLDING_ADMIN &&
companyHoldingExists;
if (!isHoldingAdminInGoodHolding) throw Boom.notFound();
if (!isHoldingAdminOfUpdatedCompanyHolding) throw Boom.notFound();
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/companies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('COMPANIES ROUTES - PUT /companies/:id', () => {
expect(response.statusCode).toBe(404);
});

it('should return 404 if billingRepresentative is from an other company and another holding', async () => {
it('should return 404 if billingRepresentative is neither from company nor holding', async () => {
const payload = { name: 'Alenvi Alenvi', billingRepresentative: usersList[1]._id };
const response = await app.inject({
method: 'PUT',
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('COMPANIES ROUTES - PUT /companies/:id', () => {
expect(response.statusCode).toBe(403);
});

it('should return 404 if billingRepresentative is from an other company and another holding', async () => {
it('should return 404 if billingRepresentative is neither from client_admin company nor holding', async () => {
const payload = { name: 'Alenvi Alenvi', billingRepresentative: usersList[1]._id };
const response = await app.inject({
method: 'PUT',
Expand Down

0 comments on commit 277e4cc

Please sign in to comment.