Skip to content

Commit

Permalink
Aftral[premieroctet#108]: fixed ae finish mission, allowed trainer to…
Browse files Browse the repository at this point in the history
… finish mission
  • Loading branch information
SeghirOumo committed Sep 5, 2024
1 parent 81cc872 commit 5184aaa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions backend/web/server/plugins/aftral-lms/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ addAction('session', getSessionAction)
// TODO dev only
if (!isProduction()) {
const forceFinishResource = async ({value, dataId}, user) => {
if([ROLE_HELPDESK, ROLE_FORMATEUR].includes(user.role) && dataId) {
user = await User.findById(dataId)
}
await Progress.findOneAndUpdate(
{user, block: value._id},
{user, block: value._id, achievement_status: BLOCK_STATUS_FINISHED},
Expand Down
11 changes: 10 additions & 1 deletion backend/web/tests/aftral-lms/block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ describe('User', () => {
//Had to copy paste from aftral-lms/actions.js

const forceFinishResource = async ({value, dataId}, user) => {
if(user.role == ROLE_HELPDESK && dataId) {
if([ROLE_HELPDESK, ROLE_FORMATEUR].includes(user.role) && dataId) {
user = await User.findById(dataId)
}
await Progress.findOneAndUpdate(
Expand All @@ -317,5 +317,14 @@ describe('User', () => {
await forceFinishResource({value:resource, dataId:trainee2._id}, helpdesk)
prog = await Progress.findOne({user:trainee2._id})
expect(prog.achievement_status == BLOCK_STATUS_FINISHED).toBeTruthy()

await Progress.findOneAndUpdate(
{user: trainee2, block: resource._id},
{user: trainee2, block: resource._id, achievement_status: BLOCK_STATUS_CURRENT},
)

await forceFinishResource({value:resource, dataId:trainee2._id}, trainer)
prog = await Progress.findOne({user:trainee2._id})
expect(prog.achievement_status == BLOCK_STATUS_FINISHED).toBeTruthy()
})
})

0 comments on commit 5184aaa

Please sign in to comment.