|
| 1 | +/* eslint-disable no-unused-expressions */ |
| 2 | +const chai = require('chai') |
| 3 | +const expect = chai.expect |
| 4 | +chai.use(require('chai-http')) |
| 5 | + |
| 6 | +const constants = require('../constants.js') |
| 7 | +const app = require('../../../src/index.js') |
| 8 | + |
| 9 | +const secretariatHeaders = { ...constants.headers, 'content-type': 'application/json' } |
| 10 | + |
| 11 | +describe('Testing Registry Org Discriminator Authority inheritance', () => { |
| 12 | + const orgsToCleanup = [] |
| 13 | + |
| 14 | + afterEach(async () => { |
| 15 | + while (orgsToCleanup.length > 0) { |
| 16 | + const shortName = orgsToCleanup.pop() |
| 17 | + try { |
| 18 | + await chai.request(app) |
| 19 | + .delete(`/api/registryOrg/${shortName}`) |
| 20 | + .set(secretariatHeaders) |
| 21 | + } catch (err) { |
| 22 | + // ignore errors during cleanup |
| 23 | + } |
| 24 | + } |
| 25 | + }) |
| 26 | + |
| 27 | + it('successfully creates a CNA organization and returns the correct authority', async () => { |
| 28 | + const cnaOrgData = { |
| 29 | + short_name: 'test_cna_discriminator', |
| 30 | + long_name: 'Test CNA Discriminator', |
| 31 | + authority: ['CNA'], |
| 32 | + hard_quota: 1000 |
| 33 | + } |
| 34 | + orgsToCleanup.push(cnaOrgData.short_name) |
| 35 | + |
| 36 | + const res = await chai.request(app) |
| 37 | + .post('/api/registry/org') |
| 38 | + .set(secretariatHeaders) |
| 39 | + .send(cnaOrgData) |
| 40 | + |
| 41 | + if (res.status !== 200) { |
| 42 | + console.log('CNA POST error res body:', JSON.stringify(res.body, null, 2)) |
| 43 | + } |
| 44 | + expect(res).to.have.status(200) |
| 45 | + expect(res.body.created).to.haveOwnProperty('authority') |
| 46 | + expect(res.body.created.authority).to.deep.equal(['CNA']) |
| 47 | + |
| 48 | + // Query it back to ensure authority was persisted |
| 49 | + const getRes = await chai.request(app) |
| 50 | + .get(`/api/registry/org/${cnaOrgData.short_name}`) |
| 51 | + .set(secretariatHeaders) |
| 52 | + |
| 53 | + expect(getRes).to.have.status(200) |
| 54 | + expect(getRes.body).to.haveOwnProperty('authority') |
| 55 | + expect(getRes.body.authority).to.deep.equal(['CNA']) |
| 56 | + }) |
| 57 | + |
| 58 | + it('successfully creates a Secretariat organization and returns the correct authority', async () => { |
| 59 | + const secretariatOrgData = { |
| 60 | + short_name: 'test_sec_discriminator', |
| 61 | + long_name: 'Test Secretariat Discriminator', |
| 62 | + authority: ['SECRETARIAT'], |
| 63 | + hard_quota: 0 |
| 64 | + } |
| 65 | + orgsToCleanup.push(secretariatOrgData.short_name) |
| 66 | + |
| 67 | + const res = await chai.request(app) |
| 68 | + .post('/api/registry/org') |
| 69 | + .set(secretariatHeaders) |
| 70 | + .send(secretariatOrgData) |
| 71 | + |
| 72 | + if (res.status !== 200) { |
| 73 | + console.log('Secretariat POST error res body:', JSON.stringify(res.body, null, 2)) |
| 74 | + } |
| 75 | + expect(res).to.have.status(200) |
| 76 | + expect(res.body.created).to.haveOwnProperty('authority') |
| 77 | + expect(res.body.created.authority).to.deep.equal(['SECRETARIAT']) |
| 78 | + |
| 79 | + // Query it back to ensure authority was persisted |
| 80 | + const getRes = await chai.request(app) |
| 81 | + .get(`/api/registry/org/${secretariatOrgData.short_name}`) |
| 82 | + .set(secretariatHeaders) |
| 83 | + |
| 84 | + expect(getRes).to.have.status(200) |
| 85 | + expect(getRes.body).to.haveOwnProperty('authority') |
| 86 | + expect(getRes.body.authority).to.deep.equal(['SECRETARIAT']) |
| 87 | + }) |
| 88 | + |
| 89 | + it('successfully creates a Root organization and returns the correct authority', async () => { |
| 90 | + const rootOrgData = { |
| 91 | + short_name: 'test_root_discriminator', |
| 92 | + long_name: 'Test Root Discriminator', |
| 93 | + authority: ['ROOT'] |
| 94 | + } |
| 95 | + orgsToCleanup.push(rootOrgData.short_name) |
| 96 | + |
| 97 | + const res = await chai.request(app) |
| 98 | + .post('/api/registry/org') |
| 99 | + .set(secretariatHeaders) |
| 100 | + .send(rootOrgData) |
| 101 | + |
| 102 | + expect(res).to.have.status(200) |
| 103 | + expect(res.body.created).to.haveOwnProperty('authority') |
| 104 | + expect(res.body.created.authority).to.deep.equal(['ROOT']) |
| 105 | + |
| 106 | + // Query it back to ensure authority was persisted |
| 107 | + const getRes = await chai.request(app) |
| 108 | + .get(`/api/registry/org/${rootOrgData.short_name}`) |
| 109 | + .set(secretariatHeaders) |
| 110 | + |
| 111 | + expect(getRes).to.have.status(200) |
| 112 | + expect(getRes.body).to.haveOwnProperty('authority') |
| 113 | + expect(getRes.body.authority).to.deep.equal(['ROOT']) |
| 114 | + }) |
| 115 | +}) |
0 commit comments