Skip to content

Commit

Permalink
Merge pull request #293 from bcgsc/feature/DEVSU-2180-change-report-t…
Browse files Browse the repository at this point in the history
…o-ready-on-edit

feature/DEVSU-2180-change-report-to-ready-on-edit
  • Loading branch information
Nithriel authored Jan 22, 2024
2 parents c5da505 + b7a3730 commit 3a73aa4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/models/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ const DEFAULT_REPORT_OPTIONS = {
transaction: options.transaction,
userId: options.userId,
}),
// If report is state "reviewed" change to "ready"
(!changed || includesAll(updateExclude, changed)) ? Promise.resolve(true)
: instance.sequelize.models.report.update({
state: 'ready',
}, {
where: {
id: (modelName === 'report') ? instance.id : instance.reportId,
state: 'reviewed',
},
individualHooks: true,
paranoid: true,
transaction: options.transaction,
userId: options.userId,
}),
]);
},
afterCreate: async (instance, options = {}) => {
Expand Down
28 changes: 28 additions & 0 deletions test/routes/report/report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,34 @@ describe('/reports/{REPORTID}', () => {
});

describe('PUT', () => {
test('state updated to ready when reviewed OK', async () => {
const res = await request
.put(`/api/reports/${reportReviewed.ident}`)
.auth(username, password)
.type('json')
.send({
tumourContent: 42.2,
})
.expect(HTTP_STATUS.OK);

checkReport(res.body);
expect(res.body).toHaveProperty('state', 'ready');
});

test('state NOT updated to ready when NOT reviewed OK', async () => {
const res = await request
.put(`/api/reports/${reportCompleted.ident}`)
.auth(username, password)
.type('json')
.send({
tumourContent: 42.2,
})
.expect(HTTP_STATUS.OK);

checkReport(res.body);
expect(res.body).toHaveProperty('state', 'completed');
});

test('tumour content update OK', async () => {
const res = await request
.put(`/api/reports/${report.ident}`)
Expand Down

0 comments on commit 3a73aa4

Please sign in to comment.