Skip to content

Commit 588a76a

Browse files
authored
Merge pull request #1812 from CVEProject/dr_1771
Resolves issue #1771, Fixes the review object history to correctly reflect modified data when an approver modifies the request during approval.
2 parents b6ba5c7 + c098b87 commit 588a76a

3 files changed

Lines changed: 59 additions & 2 deletions

File tree

src/controller/review-object.controller/review-object.controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async function approveReviewObject (req, res, next) {
117117

118118
const requestingUserUUID = await userRepo.getUserUUID(req.ctx.user, req.ctx.org, { session })
119119

120-
const reviewObj = await reviewRepo.approveReviewOrgObject(UUID, req.ctx.user, { session })
120+
const reviewObj = await reviewRepo.approveReviewOrgObject(UUID, req.ctx.user, { session }, body)
121121
if (!reviewObj) {
122122
await session.abortTransaction()
123123
return res.status(404).json({ message: `Review object not approved with UUID ${UUID}` })

src/repositories/reviewObjectRepository.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,17 @@ class ReviewObjectRepository extends BaseRepository {
183183
return _.omit(result.toObject(), ['_id', '__v'])
184184
}
185185

186-
async approveReviewOrgObject (UUID, approverUsername, options = {}) {
186+
async approveReviewOrgObject (UUID, approverUsername, options = {}, modifiedBody = null) {
187187
console.log('Approving review object with UUID:', UUID)
188188
const reviewObject = await ReviewObjectModel.findOne({ uuid: UUID }, null, options)
189189
if (!reviewObject) {
190190
return null
191191
}
192192

193+
if (modifiedBody && Object.keys(modifiedBody).length) {
194+
reviewObject.new_review_data = modifiedBody
195+
}
196+
193197
reviewObject.status = 'approved'
194198
if (approverUsername) {
195199
reviewObject.approver = {

test/integration-tests/review-object/reviewObjectTest.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('Review Object Controller Integration Tests', () => {
1414
let autoApproveReviewUUID
1515
let autoRejectReviewUUID
1616
let adminRetrievalTestReviewUUID
17+
let modifyApproveTestReviewUUID
1718

1819
context('Positive Tests', () => {
1920
it('Creates an organization to use for review object tests', async () => {
@@ -240,6 +241,58 @@ describe('Review Object Controller Integration Tests', () => {
240241
expect(res.body).to.have.property('status', 'approved')
241242
})
242243

244+
it('Nonsecretariat user can update an organization, creates review object for modify-on-approve test', async () => {
245+
const updateData = {}
246+
updateData.short_name = constants.existingOrg.short_name
247+
updateData.long_name = 'Original Pending Organization'
248+
updateData.authority = ['CNA']
249+
updateData.hard_quota = 1000
250+
const res = await chai
251+
.request(app)
252+
.put(`/api/registry/org/${constants.existingOrg.short_name}`)
253+
.set({ ...constants.nonSecretariatUserHeaders2 })
254+
.send(updateData)
255+
expect(res).to.have.status(200)
256+
257+
const reviewRes = await chai
258+
.request(app)
259+
.get(`/api/review/org/${constants.existingOrg.short_name}`)
260+
.set({ ...constants.headers })
261+
expect(reviewRes).to.have.status(200)
262+
expect(reviewRes.body).to.have.property('uuid')
263+
expect(reviewRes.body.status).to.equal('pending')
264+
expect(reviewRes.body).to.have.nested.property('new_review_data.long_name', 'Original Pending Organization')
265+
modifyApproveTestReviewUUID = reviewRes.body.uuid
266+
})
267+
268+
it('Approves a review object with modifications and updates the organization and review object history', async () => {
269+
const modifiedData = {
270+
short_name: constants.existingOrg.short_name,
271+
long_name: 'Modified Approved Organization',
272+
authority: ['CNA'],
273+
hard_quota: 2000
274+
}
275+
const res = await chai
276+
.request(app)
277+
.put(`/api/review/${modifyApproveTestReviewUUID}/approve`)
278+
.set({ ...constants.headers })
279+
.send(modifiedData)
280+
expect(res).to.have.status(200)
281+
expect(res.body).to.have.property('long_name', 'Modified Approved Organization')
282+
expect(res.body).to.have.property('hard_quota', 2000)
283+
})
284+
285+
it('Verifies the review object status is now approved and new_review_data reflects the modifications', async () => {
286+
const res = await chai
287+
.request(app)
288+
.get(`/api/review/byUUID/${modifyApproveTestReviewUUID}`)
289+
.set({ ...constants.headers })
290+
expect(res).to.have.status(200)
291+
expect(res.body).to.have.property('status', 'approved')
292+
expect(res.body).to.have.nested.property('new_review_data.long_name', 'Modified Approved Organization')
293+
expect(res.body).to.have.nested.property('new_review_data.hard_quota', 2000)
294+
})
295+
243296
it('Create new review object for rejection testing', async () => {
244297
const updateData = {}
245298
updateData.short_name = constants.existingOrg.short_name

0 commit comments

Comments
 (0)