From 48a83748c9c458efce08a2286fa547d4ddee5ebc Mon Sep 17 00:00:00 2001 From: Manon Palin Date: Mon, 27 May 2024 15:21:12 +0200 Subject: [PATCH 1/2] COM-3716 - populate trainees --- src/helpers/questionnaires.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helpers/questionnaires.js b/src/helpers/questionnaires.js index 770356c34..dab9f50e5 100644 --- a/src/helpers/questionnaires.js +++ b/src/helpers/questionnaires.js @@ -178,10 +178,11 @@ const getFollowUpForReview = async (questionnaire, courseId) => { const followUp = questionnaire.histories.map(h => pick(h, ['user', 'questionnaireAnswersList', 'timeline'])); const course = await Course.findOne({ _id: courseId }) - .select('subProgram companies misc type holding') + .select('subProgram companies misc type holding trainees') .populate({ path: 'subProgram', select: 'program', populate: [{ path: 'program', select: 'name' }] }) .populate({ path: 'companies', select: 'name' }) .populate({ path: 'holding', select: 'name' }) + .populate({ path: 'trainees', select: 'identity' }) .lean(); return { followUp, course }; From 9994e79e5ad5e48853a31adf2ff5e17ed4936fd3 Mon Sep 17 00:00:00 2001 From: Manon Palin Date: Mon, 27 May 2024 15:42:48 +0200 Subject: [PATCH 2/2] COM-3716 - add unit tests --- tests/unit/helpers/questionnaires.test.js | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/unit/helpers/questionnaires.test.js b/tests/unit/helpers/questionnaires.test.js index 330f82fab..ac5909546 100644 --- a/tests/unit/helpers/questionnaires.test.js +++ b/tests/unit/helpers/questionnaires.test.js @@ -1324,6 +1324,10 @@ describe('getFollowUp', () => { subProgram: { program: { name: 'test' } }, misc: 'infos', type: INTRA, + trainees: [ + { identity: { firstname: 'tomTom', lastname: 'Nana' } }, + { identity: { firstname: 'eleve', lastname: 'Ducobu' } }, + ], }; const cardsIds = [new ObjectId(), new ObjectId()]; const questionnaire = { @@ -1406,6 +1410,10 @@ describe('getFollowUp', () => { companies: [{ name: 'company' }], holding: [{ name: 'société mère' }], misc: 'infos', + trainees: [ + { identity: { firstname: 'tomTom', lastname: 'Nana' } }, + { identity: { firstname: 'eleve', lastname: 'Ducobu' } }, + ], }, followUp: [ { @@ -1492,14 +1500,14 @@ describe('getFollowUp', () => { courseFindOne, [ { query: 'findOne', args: [{ _id: courseId }] }, - { query: 'select', args: ['subProgram companies misc type holding'] }, + { query: 'select', args: ['subProgram companies misc type holding trainees'] }, { query: 'populate', args: [{ path: 'subProgram', select: 'program', populate: [{ path: 'program', select: 'name' }] }], }, { query: 'populate', args: [{ path: 'companies', select: 'name' }] }, { query: 'populate', args: [{ path: 'holding', select: 'name' }] }, - + { query: 'populate', args: [{ path: 'trainees', select: 'identity' }] }, { query: 'lean' }, ] ); @@ -1516,6 +1524,10 @@ describe('getFollowUp', () => { subProgram: { program: { name: 'test' } }, misc: 'infos', type: INTRA, + trainees: [ + { identity: { firstname: 'tomTom', lastname: 'Nana' } }, + { identity: { firstname: 'eleve', lastname: 'Ducobu' } }, + ], }; const questionnaire = { _id: questionnaireId, @@ -1538,6 +1550,10 @@ describe('getFollowUp', () => { companies: [{ name: 'company' }], holding: [{ name: 'société mère' }], misc: 'infos', + trainees: [ + { identity: { firstname: 'tomTom', lastname: 'Nana' } }, + { identity: { firstname: 'eleve', lastname: 'Ducobu' } }, + ], }, followUp: [], }); @@ -1571,14 +1587,14 @@ describe('getFollowUp', () => { courseFindOne, [ { query: 'findOne', args: [{ _id: courseId }] }, - { query: 'select', args: ['subProgram companies misc type holding'] }, + { query: 'select', args: ['subProgram companies misc type holding trainees'] }, { query: 'populate', args: [{ path: 'subProgram', select: 'program', populate: [{ path: 'program', select: 'name' }] }], }, { query: 'populate', args: [{ path: 'companies', select: 'name' }] }, { query: 'populate', args: [{ path: 'holding', select: 'name' }] }, - + { query: 'populate', args: [{ path: 'trainees', select: 'identity' }] }, { query: 'lean' }, ] );