|
2 | 2 | const chai = require('chai') |
3 | 3 | const chaiHttp = require('chai-http') |
4 | 4 | const app = require('../../../src/index') // Adjust path as needed |
5 | | -const { getConstants } = require('../../../src/constants') |
6 | 5 | const constants = require('../constants.js') |
7 | 6 | const expect = chai.expect |
8 | 7 |
|
9 | 8 | chai.use(chaiHttp) |
10 | 9 |
|
11 | | -// This test assumes a running server or proper mock setup usually handled by the test runner. |
12 | | -// For simplicity in this environment, we'll piggyback on existing integration test structures or |
| 10 | +// This test assumes a running server or proper mock setup usually handled by the test runner. |
| 11 | +// For simplicity in this environment, we'll piggyback on existing integration test structures or |
13 | 12 | // use a very targeted unit/repo test data if we were mocking capable. |
14 | 13 | // Given strict restriction, I will create a test that can be run with `npm test` assuming the environment handles DB. |
15 | 14 |
|
16 | 15 | describe('BaseOrgRepository Role Validation', () => { |
17 | | - // defined in constants.js |
18 | | - const secretariatHeaders = constants.headers |
19 | | - |
20 | | - // We need a known org to test against. 'mitre' usually exists in seed data. |
21 | | - const orgShortName = 'mitre' |
22 | | - |
23 | | - it('should NOT add invalid roles to an organization', async () => { |
24 | | - const res = await chai.request(app) |
25 | | - .put(`/api/org/${orgShortName}?active_roles.add=INVALID_ROLE_XXX`) |
26 | | - .set(secretariatHeaders) |
27 | | - |
28 | | - // We expect 200 OK because we decided to filter out invalid values silently, |
29 | | - // OR 400 if validation strictness was elsewhere. |
30 | | - // Based on current code, it accepts arbitrary strings. |
31 | | - // The fix will make it ignore them. |
32 | | - |
33 | | - expect(res).to.have.status(200) |
34 | | - expect(res.body.updated.authority.active_roles).to.not.include('INVALID_ROLE_XXX') |
35 | | - }) |
36 | | - |
37 | | - it('should add valid roles to an organization', async () => { |
38 | | - // Setup: assume MITRE is CNA. Let's try to add ROOT_CNA if not present, or just ensure it accepts valid enums. |
39 | | - // CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA |
40 | | - const validRole = 'ROOT_CNA' |
41 | | - |
42 | | - const res = await chai.request(app) |
43 | | - .put(`/api/org/${orgShortName}?active_roles.add=${validRole}`) |
44 | | - .set(secretariatHeaders) |
45 | | - |
46 | | - expect(res).to.have.status(200) |
47 | | - expect(res.body.updated.authority.active_roles).to.include(validRole) |
48 | | - }) |
| 16 | + // We need a known org to test against. 'mitre' usually exists in seed data. |
| 17 | + const orgShortName = 'mitre' |
| 18 | + |
| 19 | + it('should NOT add invalid roles to an organization', async () => { |
| 20 | + const res = await chai.request(app) |
| 21 | + .put(`/api/org/${orgShortName}?active_roles.add=INVALID_ROLE_XXX`) |
| 22 | + .set(constants.headers) |
| 23 | + |
| 24 | + // We expect 200 OK because we decided to filter out invalid values silently, |
| 25 | + // OR 400 if validation strictness was elsewhere. |
| 26 | + // Based on current code, it accepts arbitrary strings. |
| 27 | + // The fix will make it ignore them. |
| 28 | + |
| 29 | + expect(res).to.have.status(200) |
| 30 | + expect(res.body.updated.authority.active_roles).to.not.include('INVALID_ROLE_XXX') |
| 31 | + }) |
| 32 | + |
| 33 | + it('should add valid roles to an organization', async () => { |
| 34 | + // Setup: assume MITRE is CNA. Let's try to add ROOT_CNA if not present, or just ensure it accepts valid enums. |
| 35 | + // CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA |
| 36 | + const validRole = 'ROOT_CNA' |
| 37 | + |
| 38 | + const res = await chai.request(app) |
| 39 | + .put(`/api/org/${orgShortName}?active_roles.add=${validRole}`) |
| 40 | + .set(constants.headers) |
| 41 | + |
| 42 | + expect(res).to.have.status(200) |
| 43 | + expect(res.body.updated.authority.active_roles).to.include(validRole) |
| 44 | + }) |
49 | 45 | }) |
0 commit comments