Skip to content

Commit

Permalink
Aftral[premieroctet#81]: changed session on block to use fields from …
Browse files Browse the repository at this point in the history
…declareComputedFields
  • Loading branch information
SeghirOumo committed Aug 20, 2024
1 parent d75d7d0 commit 60d0923
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
4 changes: 2 additions & 2 deletions backend/web/server/plugins/aftral-lms/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ const getPreviousResource= async (blockId, user) => {
return {_id: brothers[0]}
}

getSession = async (userId, params, data) => {
getSession = async (userId, params, data, fields) => {
let currentBlock = data.parent
while(currentBlock.parent) {
currentBlock = await mongoose.models.block.find({_id:currentBlock.parent},{parent:1})
}
const [result] = await loadFromDb({model: 'block', id:currentBlock._id, fields:['name','spent_time_str','achievement_rule','achievement_status']})
const [result] = await loadFromDb({model: 'block', id:currentBlock._id, fields})
return result
}

Expand Down
15 changes: 3 additions & 12 deletions backend/web/tests/aftral-lms/block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Sequence = require('../../server/models/Sequence')
const Module = require('../../server/models/Module')
const Program = require('../../server/models/Program')
const Session = require('../../server/models/Session')
require('../../server/models/Certification')
const { ROLE_APPRENANT, ROLE_FORMATEUR, RESOURCE_TYPE_PDF, ACHIEVEMENT_RULE_CHECK, ACHIEVEMENT_RULE_SUCCESS, ACHIEVEMENT_RULE_CONSULT, RESOURCE_TYPE_VIDEO, ACHIEVEMENT_RULE_DOWNLOAD, ROLE_CONCEPTEUR, BLOCK_STATUS_CURRENT, BLOCK_STATUS_FINISHED, BLOCK_STATUS_UNAVAILABLE } = require('../../server/plugins/aftral-lms/consts')

jest.setTimeout(60000)
Expand All @@ -21,17 +22,7 @@ describe('User', () => {
})

it.only('must return resource session', async()=> {
const user = await User.findOne({role:ROLE_APPRENANT})
const id = '66b60f473f1ec37a3a4cd961'
const [resource] = await loadFromDb({model:'resource', user, id, fields:['session','parent']})
const [sequence] = await loadFromDb({model:'sequence', user, id:resource.parent, fields:['session','parent']})
const [modulee] = await loadFromDb({model:'module', user, id:sequence.parent, fields:['session','parent']})
const [program] = await loadFromDb({model:'program', user, id:modulee.parent, fields:['session','parent']})
const [session] = await loadFromDb({model:'session', user, id:program.parent, fields:['session','parent']})
expect(resource.session).toBeTruthy()
expect(sequence.session).toBeTruthy()
expect(modulee.session).toBeTruthy()
expect(program.session).toBeTruthy()
expect(session.session).not.toBeTruthy()
const [resource] = await loadFromDb({model: 'block', id: '66b60f473f1ec37a3a4cd961', fields:['session.name']})
expect(resource.session._id).toEqual(mongoose.Types.ObjectId('66716f3722f9dd645ff9ff53'))
})
})

0 comments on commit 60d0923

Please sign in to comment.