forked from premieroctet/openchakra
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aftral[premieroctet#111]: added evaluation resources to session
- Loading branch information
1 parent
02b99c7
commit 79f6845
Showing
5 changed files
with
107 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,30 @@ | ||
import { getBlockResources } from "./resources" | ||
const Resource = require("../../models/Resource") | ||
const Session = require("../../models/Session") | ||
const User = require("../../models/User") | ||
const { loadFromDb } = require("../../utils/database") | ||
const { getBlockResources } = require("./resources") | ||
|
||
const getEvalResources = async (userId, params, data) => { | ||
const resources = await getBlockResources (userId, params, data) | ||
console.log(resources) | ||
const getEvalResources = async (userId, params, data, fields) => { | ||
const resourceIds = await getBlockResources(data._id) | ||
const newParams = { | ||
[`filter._id`]: {$in: resourceIds}, | ||
} | ||
const user = await User.findById(userId) | ||
|
||
let resources = await loadFromDb({ | ||
model: `resource`, | ||
user, | ||
fields: [...fields, `note`, `scale`, `homework_mode`], | ||
params: newParams | ||
}) | ||
|
||
resources = resources.filter(r => | ||
r.homework_mode == true || (r.note !== undefined && r.note !== null) || (r.scale !== undefined && r.scale !== null) | ||
) | ||
|
||
return resources.map(r => new Resource(r)) | ||
} | ||
|
||
module.exports() | ||
module.exports = { | ||
getEvalResources | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ const Session = require('../../server/models/Session') | |
require('../../server/models/Certification') | ||
require('../../server/models/Permission') | ||
require('../../server/models/PermissionGroup') | ||
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, ACHIEVEMENT_RULE } = require('../../server/plugins/aftral-lms/consts') | ||
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, ACHIEVEMENT_RULE, RESOURCE_TYPE, SCALE, SCALE_NOT_ACQUIRED } = require('../../server/plugins/aftral-lms/consts') | ||
const Block = require('../../server/models/Block') | ||
const Homework = require('../../server/models/Homework') | ||
const Progress = require('../../server/models/Progress') | ||
|
@@ -23,6 +23,7 @@ jest.setTimeout(60000) | |
|
||
describe('User', () => { | ||
let trainer, trainee1, trainee2, homework1, homework2, block, progress1, progress2, sequence, modulee, program, session, productCode, conceptor, id | ||
let block2, block3, block4, block5 | ||
let limit = new Date('06-06-2025') | ||
let sequenceId | ||
beforeAll(async () => { | ||
|
@@ -55,6 +56,7 @@ describe('User', () => { | |
password: `Test`, | ||
email: `[email protected]`, | ||
}) | ||
|
||
block = await Block.create({ | ||
name: `Res`, | ||
type: `resource`, | ||
|
@@ -67,6 +69,61 @@ describe('User', () => { | |
success_note_min:0, | ||
success_note_max: 20, | ||
}) | ||
|
||
block2 = await Block.create({ | ||
name: `Res2`, | ||
type: `resource`, | ||
resource_type:RESOURCE_TYPE_PDF, | ||
url: `test`, | ||
achievement_rule:ACHIEVEMENT_RULE_CONSULT, | ||
creator: trainer._id, | ||
homework_limit_date: limit, | ||
homework_mode: false, | ||
success_note_min:0, | ||
success_note_max: 20, | ||
}) | ||
|
||
block3 = await Block.create({ | ||
name: `Res3`, | ||
type: `resource`, | ||
resource_type:RESOURCE_TYPE_PDF, | ||
url: `test`, | ||
achievement_rule:ACHIEVEMENT_RULE_CONSULT, | ||
creator: trainer._id, | ||
homework_limit_date: limit, | ||
homework_mode: false, | ||
success_note_min:0, | ||
success_note_max: 20, | ||
scale: SCALE_NOT_ACQUIRED, | ||
}) | ||
|
||
block4 = await Block.create({ | ||
name: `Res4`, | ||
type: `resource`, | ||
resource_type:RESOURCE_TYPE_PDF, | ||
url: `test`, | ||
achievement_rule:ACHIEVEMENT_RULE_CONSULT, | ||
creator: trainer._id, | ||
homework_limit_date: limit, | ||
homework_mode: false, | ||
success_note_min:0, | ||
success_note_max: 20, | ||
note: 20 | ||
}) | ||
|
||
block5 = await Block.create({ | ||
name: `Res5`, | ||
type: `resource`, | ||
resource_type:RESOURCE_TYPE_PDF, | ||
url: `test`, | ||
achievement_rule:ACHIEVEMENT_RULE_CONSULT, | ||
creator: trainer._id, | ||
homework_limit_date: limit, | ||
homework_mode: false, | ||
success_note_min:0, | ||
success_note_max: 20, | ||
}) | ||
|
||
homework1 = await Homework.create({ | ||
document: `t`, | ||
resource: block._id, | ||
|
@@ -82,7 +139,8 @@ describe('User', () => { | |
creator: trainer._id, | ||
start_date: new Date(`10-10-2024`), | ||
end_date: new Date(`10-10-2025`), | ||
trainees:[trainee1._id, trainee2._id] | ||
trainees:[trainee1._id, trainee2._id], | ||
code: `test`, | ||
}) | ||
productCode = await ProductCode.create({code:`Test product code`}) | ||
program = await Program.create({ | ||
|
@@ -99,10 +157,14 @@ describe('User', () => { | |
creator: trainer._id | ||
}) | ||
|
||
await addChildAction({parent: session._id, child: program._id}, conceptor) | ||
await addChildAction({parent: program._id, child: modulee._id}, conceptor) | ||
await addChildAction({parent: modulee._id, child: sequence._id}, conceptor) | ||
await addChildAction({parent: sequence._id, child: block._id}, conceptor) | ||
await addChildAction({parent: sequence._id, child: block2._id}, conceptor) | ||
await addChildAction({parent: sequence._id, child: block3._id}, conceptor) | ||
await addChildAction({parent: sequence._id, child: block4._id}, conceptor) | ||
await addChildAction({parent: sequence._id, child: block5._id}, conceptor) | ||
await addChildAction({parent: modulee._id, child: sequence._id}, conceptor) | ||
await addChildAction({parent: program._id, child: modulee._id}, conceptor) | ||
await addChildAction({parent: session._id, child: program._id}, conceptor) | ||
|
||
const [ses] = await loadFromDb({model: `session`, user:conceptor, fields:[`children.children.children.children`]}) | ||
id = ses.children[0].children[0].children[0].children[0]._id | ||
|
@@ -186,7 +248,7 @@ describe('User', () => { | |
expect(error).toBeDefined() | ||
}) | ||
|
||
it.only(`must accept achievement rule success for all resource types`, async () => { | ||
it(`must accept achievement rule success for all resource types`, async () => { | ||
let error | ||
try{ | ||
for(let type in RESOURCE_TYPE) { | ||
|
@@ -208,4 +270,12 @@ describe('User', () => { | |
expect(error).not.toBeTruthy() | ||
}) | ||
|
||
it.only(`must return resources on session`, async () => { | ||
const [session] = await loadFromDb({ | ||
model: `session`, | ||
user: trainer, | ||
fields: [`evaluation_resources.name`] | ||
}) | ||
expect(session.evaluation_resources.length).toEqual(3) | ||
}) | ||
}) |