diff --git a/api/tests/acceptance/application/scenario-simulator/scenario-simulator-controller_test.js b/api/tests/acceptance/application/scenario-simulator/scenario-simulator-controller_test.js index f2e22dbc919..2b8d5be4914 100644 --- a/api/tests/acceptance/application/scenario-simulator/scenario-simulator-controller_test.js +++ b/api/tests/acceptance/application/scenario-simulator/scenario-simulator-controller_test.js @@ -14,142 +14,30 @@ const { describe('Acceptance | Controller | scenario-simulator-controller', function () { let server; - let adminAuthorization; let validPayload; - - beforeEach(async function () { - const { id: adminId } = databaseBuilder.factory.buildUser.withRole({ - role: SUPER_ADMIN, - }); - - databaseBuilder.factory.buildFlashAlgorithmConfiguration({ - maximumAssessmentLength: 2, - createdAt: new Date('2022-02-01'), - }); - - adminAuthorization = generateValidRequestAuthorizationHeader(adminId); - await databaseBuilder.commit(); - - validPayload = { - capacity: 4.5, - }; - - const learningContent = { - competences: [ - { - id: 'rec1', - name_i18n: { - fr: 'comp1Fr', - en: 'comp1En', - }, - index: '1.1', - color: 'rec1Color', - skillIds: ['skill1', 'skill2'], - }, - { - id: 'rec2', - name_i18n: { - fr: 'comp2Fr', - en: 'comp2En', - }, - index: '2.1', - color: 'rec2Color', - skillIds: ['skill3', 'skill4', 'skill5'], - }, - ], - tubes: [ - { id: 'recTube1', competenceId: 'rec1' }, - { id: 'recTube2', competenceId: 'rec2' }, - ], - skills: [ - // tube 1 - { id: 'skill1', status: 'actif', tubeId: 'recTube1', competenceId: 'rec1', level: 1, pixValue: 1 }, - { id: 'skill2', status: 'actif', tubeId: 'recTube1', competenceId: 'rec1', level: 3, pixValue: 10 }, - // tube 2 - { id: 'skill3', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 2, pixValue: 100 }, - { id: 'skill4', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 3, pixValue: 1000 }, - { id: 'skill5', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 5, pixValue: 10000 }, - { id: 'skill6', status: 'périmé', tubeId: 'recTube2', competenceId: 'rec2', level: 6, pixValue: 100000 }, - ], - challenges: [ - { - id: 'challenge1', - skillId: 'skill1', - status: 'validé', - alpha: 0.16, - delta: -2, - locales: ['fr-fr'], - successProbabilityThreshold: 0.3, - }, - { - id: 'challenge2', - skillId: 'skill2', - status: 'validé', - alpha: 3, - delta: 6, - locales: ['fr-fr'], - successProbabilityThreshold: 0.4, - }, - { - id: 'challenge3', - skillId: 'skill3', - status: 'validé', - alpha: 1.587, - delta: 8.5, - locales: ['fr-fr'], - successProbabilityThreshold: 0.5, - }, - { - id: 'challenge4', - skillId: 'skill4', - status: 'validé', - alpha: 2.86789, - delta: 0.145, - locales: ['fr-fr'], - successProbabilityThreshold: 0.6, - }, - { - id: 'challenge5', - skillId: 'skill5', - status: 'validé', - alpha: 3, - delta: 1, - locales: ['fr-fr'], - successProbabilityThreshold: 0.7, - }, - { - id: 'challenge6', - skillId: 'skill5', - status: 'validé', - alpha: 1.7, - delta: -1, - locales: ['fr-fr'], - successProbabilityThreshold: 0.8, - }, - ], - }; - - mockLearningContent(learningContent); - - server = await createServer(); - }); + let options; describe('#simulateFlashAssessmentScenario', function () { - let options; - beforeEach(async function () { - options = { - method: 'POST', - url: `/api/scenario-simulator`, - payload: {}, - headers: {}, - }; + server = await createServer(); }); it('should return a report with the same number of simulation scenario reports as the number of challenges in the configuration', async function () { // given - options.headers.authorization = adminAuthorization; - options.payload = validPayload; + const adminAuthorization = _buildSuperAdminUser(); + _buildLearningContent(); + await _buildAlgorithmConfiguration(); + + const options = { + method: 'POST', + url: `/api/scenario-simulator`, + payload: { + capacity: 4.5, + }, + headers: { + authorization: adminAuthorization, + }, + }; // when const response = await server.inject(options); @@ -170,6 +58,10 @@ describe('Acceptance | Controller | scenario-simulator-controller', function () describe('when there is no connected user', function () { it('should return status code 401', async function () { // given + databaseBuilder.factory.buildUser.withRole({ + role: SUPER_ADMIN, + }); + await databaseBuilder.commit(); options.headers.authorization = undefined; // when @@ -199,7 +91,9 @@ describe('Acceptance | Controller | scenario-simulator-controller', function () describe('when request payload is invalid', function () { it('should return status code 400', async function () { // given - options.headers.authorization = adminAuthorization; + const { id: userId } = databaseBuilder.factory.buildUser(); + await databaseBuilder.commit(); + options.headers.authorization = generateValidRequestAuthorizationHeader(userId); options.payload = { wrongField: [], }; @@ -213,3 +107,119 @@ describe('Acceptance | Controller | scenario-simulator-controller', function () }); }); }); + +function _buildSuperAdminUser() { + const userId = databaseBuilder.factory.buildUser.withRole({ + role: SUPER_ADMIN, + }).id; + + return generateValidRequestAuthorizationHeader(userId); +} + +async function _buildAlgorithmConfiguration() { + databaseBuilder.factory.buildFlashAlgorithmConfiguration({ + maximumAssessmentLength: 2, + createdAt: new Date('2022-02-01'), + }); + + await databaseBuilder.commit(); +} + +function _buildLearningContent() { + const learningContent = { + competences: [ + { + id: 'rec1', + name_i18n: { + fr: 'comp1Fr', + en: 'comp1En', + }, + index: '1.1', + color: 'rec1Color', + skillIds: ['skill1', 'skill2'], + }, + { + id: 'rec2', + name_i18n: { + fr: 'comp2Fr', + en: 'comp2En', + }, + index: '2.1', + color: 'rec2Color', + skillIds: ['skill3', 'skill4', 'skill5'], + }, + ], + tubes: [ + { id: 'recTube1', competenceId: 'rec1' }, + { id: 'recTube2', competenceId: 'rec2' }, + ], + skills: [ + // tube 1 + { id: 'skill1', status: 'actif', tubeId: 'recTube1', competenceId: 'rec1', level: 1, pixValue: 1 }, + { id: 'skill2', status: 'actif', tubeId: 'recTube1', competenceId: 'rec1', level: 3, pixValue: 10 }, + // tube 2 + { id: 'skill3', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 2, pixValue: 100 }, + { id: 'skill4', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 3, pixValue: 1000 }, + { id: 'skill5', status: 'actif', tubeId: 'recTube2', competenceId: 'rec2', level: 5, pixValue: 10000 }, + { id: 'skill6', status: 'périmé', tubeId: 'recTube2', competenceId: 'rec2', level: 6, pixValue: 100000 }, + ], + challenges: [ + { + id: 'challenge1', + skillId: 'skill1', + status: 'validé', + alpha: 0.16, + delta: -2, + locales: ['fr-fr'], + successProbabilityThreshold: 0.3, + }, + { + id: 'challenge2', + skillId: 'skill2', + status: 'validé', + alpha: 3, + delta: 6, + locales: ['fr-fr'], + successProbabilityThreshold: 0.4, + }, + { + id: 'challenge3', + skillId: 'skill3', + status: 'validé', + alpha: 1.587, + delta: 8.5, + locales: ['fr-fr'], + successProbabilityThreshold: 0.5, + }, + { + id: 'challenge4', + skillId: 'skill4', + status: 'validé', + alpha: 2.86789, + delta: 0.145, + locales: ['fr-fr'], + successProbabilityThreshold: 0.6, + }, + { + id: 'challenge5', + skillId: 'skill5', + status: 'validé', + alpha: 3, + delta: 1, + locales: ['fr-fr'], + successProbabilityThreshold: 0.7, + }, + { + id: 'challenge6', + skillId: 'skill5', + status: 'validé', + alpha: 1.7, + delta: -1, + locales: ['fr-fr'], + successProbabilityThreshold: 0.8, + }, + ], + }; + + mockLearningContent(learningContent); +}