Skip to content

Commit f967daa

Browse files
author
jack-flores
committed
#1258 all tests passing
1 parent a85cbb9 commit f967daa

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

src/controller/org.controller/org.controller.js

-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ async function createOrg (req, res, next) {
322322
* Called by PUT /api/org/{shortname}
323323
**/
324324
async function updateOrg (req, res, next) {
325-
console.log("in controller") // todo: delete
326325
try {
327326
const shortName = req.ctx.params.shortname
328327
const newOrg = new Org()
@@ -431,7 +430,6 @@ async function updateOrg (req, res, next) {
431430
logger.info(JSON.stringify(payload))
432431
return res.status(200).json(responseMessage)
433432
} catch (err) {
434-
console.log("err in congtroller: " + err) // todo: delete
435433
next(err)
436434
}
437435
}

src/middleware/middleware.js

-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ async function validateUser (req, res, next) {
107107
logger.info({ uuid: req.ctx.uuid, message: 'Authenticating user: ' + user }) // userUUID may be null if user does not exist
108108
const orgUUID = await orgRepo.getOrgUUID(org)
109109
if (!orgUUID) {
110-
console.log("401 1: " + org + " is was not in db ") // todo: delete
111110
logger.info({ uuid: req.ctx.uuid, message: org + ' organization does not exist. User authentication FAILED for ' + user })
112111
return res.status(401).json(error.unauthorized())
113112
}
@@ -148,7 +147,6 @@ async function validateOrg (req, res, next) {
148147
const isSec = await orgRepo.isSecretariat(org)
149148
if (!isSec) {
150149
if (!(org == reqOrg)) {
151-
console.log(org + " is not a sec and is not equal to " + reqOrg) // todo: delete
152150
logger.info({ uuid: req.ctx.uuid, message: org + ' is not a ' + CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT + ' or the same as ' + reqOrg + ' and is not allowed to make these changes.' })
153151
return res.status(401).json(error.unauthorized())
154152
}

test/integration-tests/org/putOrgTest.js

+52-5
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,77 @@ const expect = chai.expect
55
const constants = require('../constants.js')
66
const app = require('../../../src/index.js')
77

8-
const params = {new_short_name: 'test_org', name: 'Test Organization', id_quota: 100000}
8+
const params = { name: 'Test Organization', id_quota: 100 }
9+
const secretariat_params = { name: 'MITRE Corporation', id_quota: 100000 }
10+
const cna_params = { name: 'Adams, Nielsen and Hensley', id_quota: 1309 }
911

1012
describe('Testing org put endpoint', () => {
1113
context('Positive Tests', () => {
1214
it('Allows update made by a secretariat to itself', async () => {
1315
await chai.request(app)
1416
.put('/api/org/mitre')
1517
.set({ ...constants.headers })
16-
.query({id_quota: '100000'})
18+
.query(params)
1719
.send()
1820
.then((res, err) => {
19-
console.log(res.text)
2021
expect(res).to.have.status(200)
22+
expect(res.body.updated.name).to.equal(params.name)
2123
expect(res.body.updated.policies.id_quota).to.equal(params.id_quota)
2224
expect(err).to.be.undefined
2325
})
26+
await chai.request(app)
27+
.put(`/api/org/mitre`)
28+
.set({ ...constants.headers })
29+
.query(secretariat_params)
30+
.send()
31+
.then((res, err) => {
32+
expect(res).to.have.status(200)
33+
expect(res.body.updated.name).to.equal(secretariat_params.name)
34+
expect(res.body.updated.policies.id_quota).to.equal(secretariat_params.id_quota)
35+
expect(err).to.be.undefined
36+
})
2437
})
2538
it('Allows update made by a secretariat to another org', async () => {
2639
await chai.request(app)
27-
.put('/api/org/cause_8')
40+
.put('/api/org/win_5')
2841
.set({ ...constants.headers })
42+
.query(params)
2943
.send()
3044
.then((res, err) => {
3145
expect(res).to.have.status(200)
46+
expect(res.body.updated.name).to.equal(params.name)
47+
expect(res.body.updated.policies.id_quota).to.equal(params.id_quota)
48+
expect(err).to.be.undefined
49+
})
50+
await chai.request(app)
51+
.put('/api/org/win_5')
52+
.set({ ...constants.headers })
53+
.query(cna_params)
54+
.send()
55+
.then((res, err) => {
56+
expect(res).to.have.status(200)
57+
expect(res.body.updated.name).to.equal(cna_params.name)
58+
expect(res.body.updated.policies.id_quota).to.equal(cna_params.id_quota)
3259
expect(err).to.be.undefined
3360
})
3461
})
35-
it('Allows update made by non secretariat org to itself', async () => {
62+
it('Update made by non secretariat org to itself ONLY updates last_active field', async () => {
63+
let now = Date.now()
3664
await chai.request(app)
3765
.put('/api/org/win_5')
3866
.set({ ...constants.nonSecretariatUserHeaders })
67+
.query(params)
3968
.send()
4069
.then((res, err) => {
70+
// Assert that that the last_active field was updated under 2 seconds ago
71+
let last_active = Date.parse(res.body.updated.last_active)
72+
let diff = Math.abs(now - last_active)
73+
let within_two_seconds = diff < 2000
74+
expect(within_two_seconds).to.be.true
75+
// Assert no other fields were changed
4176
expect(res).to.have.status(200)
77+
expect(res.body.updated.name).to.equal(cna_params.name)
78+
expect(res.body.updated.policies.id_quota).to.equal(cna_params.id_quota)
4279
expect(err).to.be.undefined
4380
})
4481
})
@@ -54,5 +91,15 @@ describe('Testing org put endpoint', () => {
5491
expect(err).to.be.undefined
5592
})
5693
})
94+
it('Fails update made by a non-secretariat org to a secretariat', async () => {
95+
await chai.request(app)
96+
.put('/api/org/mitre')
97+
.set({ ...constants.nonSecretariatUserHeaders })
98+
.send()
99+
.then((res, err) => {
100+
expect(res).to.have.status(401)
101+
expect(err).to.be.undefined
102+
})
103+
})
57104
})
58105
})

0 commit comments

Comments
 (0)