Skip to content

Commit 03cc618

Browse files
author
jack-flores
committed
#1258 updated swagger documentation
1 parent 403b3bf commit 03cc618

File tree

3 files changed

+96
-4
lines changed

3 files changed

+96
-4
lines changed

src/controller/org.controller/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ router.put('/org/:shortname',
247247
<h2>Access Control</h2>
248248
<p>User must belong to an organization with the <b>Secretariat</b> role</p>
249249
<h2>Expected Behavior</h2>
250+
<p><b>CNA:</b> Updates 'last_active' timestamp to show that a CNA is still active</p>
250251
<p><b>Secretariat:</b> Updates any organization's information</p>"
251252
#swagger.parameters['shortname'] = { description: 'The shortname of the organization' }
252253
#swagger.parameters['$ref'] = [

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ async function updateOrg (req, res, next) {
338338
return res.status(404).json(error.orgDnePathParam(shortName))
339339
}
340340

341-
newOrg.last_active = Date.now()
342341
const isSec = await orgRepo.isSecretariat(orgMakingChanges)
343342

344343
if (isSec) {
@@ -399,6 +398,8 @@ async function updateOrg (req, res, next) {
399398
}
400399
}
401400

401+
newOrg.last_active = Date.now()
402+
402403
// update org
403404
let result = await orgRepo.updateByOrgUUID(org.UUID, newOrg)
404405
if (result.n === 0) {

test/unit-tests/org/orgUpdateTest.js

+93-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-unused-expressions */
12
const express = require('express')
23
const app = express()
34
const chai = require('chai')
@@ -38,7 +39,9 @@ class OrgUpdatedAddingRole {
3839
}
3940

4041
async aggregate () {
41-
return [orgFixtures.owningOrg]
42+
const org = orgFixtures.owningOrg
43+
org.last_active = Date.now()
44+
return [org]
4245
}
4346

4447
async updateByOrgUUID () {
@@ -60,7 +63,9 @@ class OrgUpdatedRemovingRole {
6063
}
6164

6265
async aggregate () {
63-
return [orgFixtures.owningOrg]
66+
const org = orgFixtures.owningOrg
67+
org.last_active = Date.now()
68+
return [org]
6469
}
6570

6671
async updateByOrgUUID () {
@@ -172,6 +177,11 @@ describe('Testing the PUT /org/:shortname endpoint in Org Controller', () => {
172177
expect(res.body.updated.name).to.equal(orgFixtures.owningOrg.name)
173178
expect(res.body.updated.UUID).to.equal(orgFixtures.owningOrg.UUID)
174179
expect(res.body.updated.policies.id_quota).to.equal(orgFixtures.owningOrg.policies.id_quota)
180+
const now = Date.now()
181+
const lastActive = res.body.updated.last_active
182+
const diff = Math.abs(now - lastActive)
183+
const withinTwoSeconds = diff < 500
184+
expect(withinTwoSeconds).to.be.true
175185
done()
176186
})
177187
})
@@ -207,6 +217,11 @@ describe('Testing the PUT /org/:shortname endpoint in Org Controller', () => {
207217
expect(res.body.updated.name).to.equal(orgFixtures.owningOrg.name)
208218
expect(res.body.updated.UUID).to.equal(orgFixtures.owningOrg.UUID)
209219
expect(res.body.updated.policies.id_quota).to.equal(orgFixtures.owningOrg.policies.id_quota)
220+
const now = Date.now()
221+
const lastActive = res.body.updated.last_active
222+
const diff = Math.abs(now - lastActive)
223+
const withinTwoSeconds = diff < 500
224+
expect(withinTwoSeconds).to.be.true
210225
done()
211226
})
212227
})
@@ -241,6 +256,11 @@ describe('Testing the PUT /org/:shortname endpoint in Org Controller', () => {
241256
expect(res.body.updated.name).to.equal(orgFixtures.owningOrg.name)
242257
expect(res.body.updated.UUID).to.equal(orgFixtures.owningOrg.UUID)
243258
expect(res.body.updated.policies.id_quota).to.equal(orgFixtures.owningOrg.policies.id_quota)
259+
const now = Date.now()
260+
const lastActive = res.body.updated.last_active
261+
const diff = Math.abs(now - lastActive)
262+
const withinTwoSeconds = diff < 500
263+
expect(withinTwoSeconds).to.be.true
244264
done()
245265
})
246266
})
@@ -275,6 +295,11 @@ describe('Testing the PUT /org/:shortname endpoint in Org Controller', () => {
275295
expect(res.body.updated.name).to.equal(orgFixtures.owningOrg.name)
276296
expect(res.body.updated.UUID).to.equal(orgFixtures.owningOrg.UUID)
277297
expect(res.body.updated.policies.id_quota).to.equal(orgFixtures.owningOrg.policies.id_quota)
298+
const now = Date.now()
299+
const lastActive = res.body.updated.last_active
300+
const diff = Math.abs(now - lastActive)
301+
const withinTwoSeconds = diff < 500
302+
expect(withinTwoSeconds).to.be.true
278303
done()
279304
})
280305
})
@@ -295,7 +320,9 @@ describe('Testing the PUT /org/:shortname endpoint in Org Controller', () => {
295320
}
296321

297322
async aggregate () {
298-
return [orgFixtures.existentOrg]
323+
const org = orgFixtures.existentOrg
324+
org.last_active = Date.now()
325+
return [org]
299326
}
300327

301328
async isSecretariat () {
@@ -328,6 +355,69 @@ describe('Testing the PUT /org/:shortname endpoint in Org Controller', () => {
328355
expect(res.body.updated.name).to.equal(orgFixtures.existentOrg.name)
329356
expect(res.body.updated.short_name).to.equal(orgFixtures.existentOrg.short_name)
330357
expect(res.body.updated.UUID).to.equal(orgFixtures.existentOrg.UUID)
358+
const now = Date.now()
359+
const lastActive = res.body.updated.last_active
360+
const diff = Math.abs(now - lastActive)
361+
const withinTwoSeconds = diff < 500
362+
expect(withinTwoSeconds).to.be.true
363+
})
364+
365+
it('Non-secretariat only last_active field updated', (done) => {
366+
class NonSecretariat {
367+
async findOneByShortName () {
368+
return orgFixtures.owningOrg
369+
}
370+
371+
async aggregate () {
372+
const org = orgFixtures.owningOrg
373+
org.last_active = Date.now()
374+
return [org]
375+
}
376+
377+
async updateByOrgUUID () {
378+
return { n: 1 }
379+
}
380+
381+
async getOrgUUID () {
382+
return null
383+
}
384+
385+
async isSecretariat () {
386+
return false
387+
}
388+
}
389+
app.route('/org-non-secretariat-updates-last-active-field/:shortname')
390+
.put((req, res, next) => {
391+
const factory = {
392+
getOrgRepository: () => { return new NonSecretariat() },
393+
getUserRepository: () => { return new NullUserRepo() }
394+
}
395+
req.ctx.repositories = factory
396+
next()
397+
}, orgParams.parsePostParams, orgController.ORG_UPDATE_SINGLE)
398+
399+
chai.request(app)
400+
.put(`/org-non-secretariat-updates-last-active-field/${orgFixtures.owningOrg.short_name}?name=TestOrg`)
401+
.set(orgFixtures.owningOrgHeader)
402+
.end((err, res) => {
403+
if (err) {
404+
done(err)
405+
}
406+
expect(res).to.have.status(200)
407+
expect(res).to.have.property('body').and.to.be.a('object')
408+
expect(res.body).to.have.property('updated').and.to.be.a('object')
409+
// Assert that that the last_active field was updated under 0.5 seconds ago
410+
const now = Date.now()
411+
const lastActive = res.body.updated.last_active
412+
const diff = Math.abs(now - lastActive)
413+
const withinTwoSeconds = diff < 500
414+
expect(withinTwoSeconds).to.be.true
415+
// Assert no other fields were changed
416+
expect(res.body.updated.active_roles).to.be.undefined
417+
expect(res.body.updated.name).to.be.undefined
418+
expect(res.body.updated.policies).to.be.undefined
419+
done()
420+
})
331421
})
332422
})
333423
})

0 commit comments

Comments
 (0)