diff --git a/schemas/registry-org/BaseOrg.json b/schemas/registry-org/BaseOrg.json index aab61eba1..7f1b8c000 100644 --- a/schemas/registry-org/BaseOrg.json +++ b/schemas/registry-org/BaseOrg.json @@ -183,7 +183,8 @@ "format": "date" }, "status": { - "type": "string" + "type": "string", + "enum": ["active", "inactive", "pending"] } }, "additionalProperties": false diff --git a/schemas/registry-org/create-registry-org-request.json b/schemas/registry-org/create-registry-org-request.json index b1917cf18..9a57cafb9 100644 --- a/schemas/registry-org/create-registry-org-request.json +++ b/schemas/registry-org/create-registry-org-request.json @@ -184,7 +184,8 @@ "format": "date" }, "status": { - "type": "string" + "type": "string", + "enum": ["active", "inactive", "pending"] } }, "description": "Additional partner metadata (restricted)" diff --git a/schemas/registry-org/get-registry-org-response.json b/schemas/registry-org/get-registry-org-response.json index 86fc75326..205889cbf 100644 --- a/schemas/registry-org/get-registry-org-response.json +++ b/schemas/registry-org/get-registry-org-response.json @@ -150,7 +150,8 @@ "format": "date" }, "status": { - "type": "string" + "type": "string", + "enum": ["active", "inactive", "pending"] } }, "description": "Additional partner metadata (restricted)" diff --git a/schemas/registry-org/list-registry-orgs-response.json b/schemas/registry-org/list-registry-orgs-response.json index e4956e545..c8eb6d162 100644 --- a/schemas/registry-org/list-registry-orgs-response.json +++ b/schemas/registry-org/list-registry-orgs-response.json @@ -172,7 +172,8 @@ "format": "date" }, "status": { - "type": "string" + "type": "string", + "enum": ["active", "inactive", "pending"] } }, "description": "Additional partner metadata (restricted)" diff --git a/schemas/registry-org/update-registry-org-request.json b/schemas/registry-org/update-registry-org-request.json index f388a40f7..6e9ce77d2 100644 --- a/schemas/registry-org/update-registry-org-request.json +++ b/schemas/registry-org/update-registry-org-request.json @@ -200,7 +200,8 @@ "format": "date" }, "status": { - "type": "string" + "type": "string", + "enum": ["active", "inactive", "pending"] } }, "description": "Additional partner metadata (restricted)" diff --git a/src/model/baseorg.js b/src/model/baseorg.js index ee690878c..3d96d9406 100644 --- a/src/model/baseorg.js +++ b/src/model/baseorg.js @@ -41,7 +41,7 @@ const schema = { cve_website_update_needed: Boolean, partner_active_date: String, partner_inactive_date: String, - status: String + status: { type: String, enum: ['active', 'inactive', 'pending'] } }, advisory_locations: [String], advisory_location_require_credentials: Boolean, diff --git a/test/unit-tests/org/baseOrgRepositoryTest.js b/test/unit-tests/org/baseOrgRepositoryTest.js index cad1297d7..8446b525a 100644 --- a/test/unit-tests/org/baseOrgRepositoryTest.js +++ b/test/unit-tests/org/baseOrgRepositoryTest.js @@ -69,4 +69,43 @@ describe('Testing BaseOrgRepository', () => { select ]) }) + + it('accepts every supported program data status', () => { + const repository = new BaseOrgRepository() + + for (const status of ['active', 'inactive', 'pending']) { + const org = { + short_name: 'example-org', + id_quota: 1, + authority: ['CNA'], + program_data: { status } + } + + expect(repository.validateOrg(org).isValid, status).to.equal(true) + expect(new BaseOrgModel({ program_data: { status } }).validateSync(), status).to.equal(undefined) + } + }) + + it('rejects an unsupported program data status', () => { + const repository = new BaseOrgRepository() + const org = { + short_name: 'example-org', + id_quota: 1, + authority: ['CNA'], + program_data: { status: 'archived' } + } + + const schemaResult = repository.validateOrg(org) + expect(schemaResult.isValid).to.equal(false) + expect(schemaResult.errors).to.deep.include({ + instancePath: '/program_data/status', + schemaPath: '/BaseOrg#/properties/program_data/properties/status/enum', + keyword: 'enum', + params: { allowedValues: ['active', 'inactive', 'pending'] }, + message: 'must be equal to one of the allowed values' + }) + + const validationError = new BaseOrgModel({ program_data: { status: 'archived' } }).validateSync() + expect(validationError.errors['program_data.status'].kind).to.equal('enum') + }) })