Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/repositories/baseOrgRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,23 @@ class BaseOrgRepository extends BaseRepository {
return { isValid: false, errors: [{ instancePath: '/authority', message: 'authority is required' }] }
}

const validAuthorityRoles = getConstants().ORG_ROLES
const authorityRoleError = instancePath => ({
isValid: false,
errors: [{
instancePath,
message: 'must be equal to one of the allowed values',
params: { allowedValues: validAuthorityRoles }
}]
})

let validateObject = {}
if (Array.isArray(org.authority)) {
const invalidAuthorityIndex = org.authority.findIndex(role => !validAuthorityRoles.includes(role))
if (invalidAuthorityIndex !== -1) {
return authorityRoleError(`/authority/${invalidAuthorityIndex}`)
}

// User passed in an array, we need to decide how we handle this.
if (org.authority.includes('SECRETARIAT')) {
org.authority = ['SECRETARIAT']
Expand All @@ -1068,6 +1083,10 @@ class BaseOrgRepository extends BaseRepository {
}
}
} else {
if (!validAuthorityRoles.includes(org.authority)) {
return authorityRoleError('/authority')
}

if (org.authority === 'ADP') {
validateObject = ADPOrgModel.validateOrg(org)
}
Expand Down
17 changes: 17 additions & 0 deletions test/integration-tests/registry-org/registryOrgCRUDTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,23 @@ describe('Testing /registryOrg endpoints', () => {
expect(res.body.message).to.equal('Parameters were invalid')
})
})
it('Fails to update a registry organization with lowercase authority and returns authority errors', async () => {
await chai.request(app)
.put('/api/registry/org/registry_org_test')
.set(secretariatHeaders)
.send({
...createdOrg,
authority: ['cna']
})
.then((res) => {
expect(res).to.have.status(400)
expect(res.body.message).to.equal('Parameters were invalid')
expect(res.body.errors).to.be.an('array')
expect(res.body.errors[0].instancePath).to.equal('/authority/0')
expect(res.body.errors[0].message).to.equal('must be equal to one of the allowed values')
expect(res.body.errors[0].params.allowedValues).to.include('CNA')
})
})
it('Fails to update a registry organization providing an invalid partner_role_type enum value', async () => {
await chai.request(app)
.put('/api/registry/org/registry_org_test')
Expand Down
Loading