From 7cea5f93bcc99e18a7fe4acc3a84905ed4567c97 Mon Sep 17 00:00:00 2001 From: Alexandre COIN Date: Fri, 15 Nov 2024 11:37:06 +0100 Subject: [PATCH] refactor(api): remove useObsoleteChallenges parameter --- .../scenario-simulator-controller.js | 2 - .../application/scenario-simulator-route.js | 1 - .../simulate-flash-assessment-scenario.js | 3 +- .../repositories/challenge-repository.js | 8 -- .../repositories/challenge-repository_test.js | 100 ------------------ ...simulate-flash-assessment-scenario_test.js | 8 +- 6 files changed, 5 insertions(+), 117 deletions(-) diff --git a/api/src/certification/flash-certification/application/scenario-simulator-controller.js b/api/src/certification/flash-certification/application/scenario-simulator-controller.js index a9ff01c4099..0804f182f16 100644 --- a/api/src/certification/flash-certification/application/scenario-simulator-controller.js +++ b/api/src/certification/flash-certification/application/scenario-simulator-controller.js @@ -25,7 +25,6 @@ async function simulateFlashAssessmentScenario( stopAtChallenge, initialCapacity, numberOfIterations = 1, - useObsoleteChallenges, challengePickProbability, challengesBetweenSameCompetence, limitToOneQuestionPerTube, @@ -58,7 +57,6 @@ async function simulateFlashAssessmentScenario( locale, stopAtChallenge, initialCapacity, - useObsoleteChallenges, challengesBetweenSameCompetence, limitToOneQuestionPerTube, minimumEstimatedSuccessRateRanges, diff --git a/api/src/certification/flash-certification/application/scenario-simulator-route.js b/api/src/certification/flash-certification/application/scenario-simulator-route.js index fe2af02713d..dee25a79a74 100644 --- a/api/src/certification/flash-certification/application/scenario-simulator-route.js +++ b/api/src/certification/flash-certification/application/scenario-simulator-route.js @@ -13,7 +13,6 @@ const _baseScenarioParametersValidator = Joi.object().keys({ initialCapacity: Joi.number().integer().min(-8).max(8), stopAtChallenge: Joi.number().integer().min(0), numberOfIterations: Joi.number().integer().min(0), - useObsoleteChallenges: Joi.boolean(), challengePickProbability: Joi.number().min(0).max(100), challengesBetweenSameCompetence: Joi.number().min(0), limitToOneQuestionPerTube: Joi.boolean(), diff --git a/api/src/certification/flash-certification/domain/usecases/simulate-flash-assessment-scenario.js b/api/src/certification/flash-certification/domain/usecases/simulate-flash-assessment-scenario.js index 9cbb23e31be..310c755d715 100644 --- a/api/src/certification/flash-certification/domain/usecases/simulate-flash-assessment-scenario.js +++ b/api/src/certification/flash-certification/domain/usecases/simulate-flash-assessment-scenario.js @@ -10,7 +10,6 @@ export async function simulateFlashAssessmentScenario({ pickAnswerStatus, stopAtChallenge, initialCapacity, - useObsoleteChallenges, challengesBetweenSameCompetence = 0, limitToOneQuestionPerTube = true, minimumEstimatedSuccessRateRanges = [], @@ -21,7 +20,7 @@ export async function simulateFlashAssessmentScenario({ challengeRepository, flashAlgorithmService, }) { - const challenges = await challengeRepository.findFlashCompatible({ locale, useObsoleteChallenges }); + const challenges = await challengeRepository.findActiveFlashCompatible({ locale }); const flashAssessmentAlgorithm = new FlashAssessmentAlgorithm({ flashAlgorithmImplementation: flashAlgorithmService, diff --git a/api/src/shared/infrastructure/repositories/challenge-repository.js b/api/src/shared/infrastructure/repositories/challenge-repository.js index c17f7d2207d..f0e7fcb1b99 100644 --- a/api/src/shared/infrastructure/repositories/challenge-repository.js +++ b/api/src/shared/infrastructure/repositories/challenge-repository.js @@ -105,13 +105,6 @@ const findOperativeFlashCompatible = async function ({ return _toDomainCollection({ challengeDataObjects, skills, successProbabilityThreshold }); }; -const findFlashCompatible = async function ({ locale, useObsoleteChallenges } = {}) { - _assertLocaleIsDefined(locale); - const challengeDataObjects = await challengeDatasource.findFlashCompatible({ locale, useObsoleteChallenges }); - const skills = await skillDatasource.list(); - return _toDomainCollection({ challengeDataObjects, skills }); -}; - const findFlashCompatibleWithoutLocale = async function ({ useObsoleteChallenges } = {}) { const challengeDataObjects = await challengeDatasource.findFlashCompatibleWithoutLocale({ useObsoleteChallenges }); const skills = await skillDatasource.list(); @@ -132,7 +125,6 @@ export async function getManyTypes(ids) { export { findActiveFlashCompatible, - findFlashCompatible, findFlashCompatibleWithoutLocale, findOperative, findOperativeBySkills, diff --git a/api/tests/shared/integration/infrastructure/repositories/challenge-repository_test.js b/api/tests/shared/integration/infrastructure/repositories/challenge-repository_test.js index 4c6ea744ea7..be30b40e119 100644 --- a/api/tests/shared/integration/infrastructure/repositories/challenge-repository_test.js +++ b/api/tests/shared/integration/infrastructure/repositories/challenge-repository_test.js @@ -473,106 +473,6 @@ describe('Integration | Repository | challenge-repository', function () { }); }); - describe('#findFlashCompatible', function () { - beforeEach(function () { - // given - const skill = domainBuilder.buildSkill({ id: 'recSkill1' }); - const locales = ['fr-fr']; - const activeChallenge = domainBuilder.buildChallenge({ - id: 'activeChallenge', - skill, - status: 'validé', - locales, - }); - const archivedChallenge = domainBuilder.buildChallenge({ - id: 'archivedChallenge', - skill, - status: 'archivé', - locales, - }); - const outdatedChallenge = domainBuilder.buildChallenge({ - id: 'outdatedChallenge', - skill, - status: 'périmé', - locales, - }); - const learningContent = { - skills: [{ ...skill, status: 'actif', level: skill.difficulty }], - challenges: [ - { ...activeChallenge, skillId: 'recSkill1', alpha: 3.57, delta: -8.99 }, - { ...archivedChallenge, skillId: 'recSkill1', alpha: 3.2, delta: 1.06 }, - { ...outdatedChallenge, skillId: 'recSkill1', alpha: 4.1, delta: -2.08 }, - ], - }; - mockLearningContent(learningContent); - }); - - context('without requesting obsolete challenges', function () { - it('should return all flash compatible challenges with skills', async function () { - // given - const locale = 'fr-fr'; - - // when - const actualChallenges = await challengeRepository.findFlashCompatible({ - locale, - }); - - // then - expect(actualChallenges).to.have.lengthOf(2); - expect(actualChallenges[0]).to.be.instanceOf(Challenge); - expect(actualChallenges[0]).to.deep.contain({ - status: 'validé', - }); - expect(actualChallenges[1]).to.deep.contain({ - status: 'archivé', - }); - }); - - it('should allow overriding success probability threshold default value', async function () { - // given - const successProbabilityThreshold = 0.75; - - // when - const actualChallenges = await challengeRepository.findActiveFlashCompatible({ - locale: 'fr-fr', - successProbabilityThreshold, - }); - - // then - expect(actualChallenges).to.have.lengthOf(1); - expect(actualChallenges[0]).to.be.instanceOf(Challenge); - expect(actualChallenges[0].minimumCapability).to.equal(-8.682265465359073); - }); - }); - - context('when requesting obsolete challenges', function () { - it('should return all flash compatible challenges with skills', async function () { - // given - const locale = 'fr-fr'; - - // when - const actualChallenges = await challengeRepository.findFlashCompatible({ - locale, - useObsoleteChallenges: true, - }); - - // then - expect(actualChallenges).to.have.lengthOf(3); - expect(actualChallenges[0]).to.be.instanceOf(Challenge); - expect(actualChallenges[0]).to.deep.contain({ - status: 'validé', - }); - expect(actualChallenges[1]).to.deep.contain({ - status: 'archivé', - }); - - expect(actualChallenges[2]).to.deep.contain({ - status: 'périmé', - }); - }); - }); - }); - describe('#findFlashCompatibleWithoutLocale', function () { beforeEach(function () { // given diff --git a/api/tests/unit/domain/usecases/simulate-flash-assessment-scenario_test.js b/api/tests/unit/domain/usecases/simulate-flash-assessment-scenario_test.js index 99d21c6bf71..20aa7d1dbfd 100644 --- a/api/tests/unit/domain/usecases/simulate-flash-assessment-scenario_test.js +++ b/api/tests/unit/domain/usecases/simulate-flash-assessment-scenario_test.js @@ -229,9 +229,9 @@ describe('Unit | UseCase | simulate-flash-assessment-scenario', function () { const enablePassageByAllCompetences = false; const challenge = domainBuilder.buildChallenge({ id: 1 }); const challengeRepository = { - findFlashCompatible: sinon.stub(), + findActiveFlashCompatible: sinon.stub(), }; - challengeRepository.findFlashCompatible.resolves([challenge]); + challengeRepository.findActiveFlashCompatible.resolves([challenge]); const pickChallenge = sinon.stub(); const pickAnswerStatus = sinon.stub(); @@ -321,7 +321,7 @@ function prepareStubs({ const allChallenges = [firstChallenge, secondChallenge, thirdChallenge]; const challengeRepository = { - findFlashCompatible: sinon.stub(), + findActiveFlashCompatible: sinon.stub(), }; const pickChallenge = sinon.stub(); const pickAnswerStatus = sinon.stub(); @@ -430,7 +430,7 @@ function prepareStubs({ .returns([thirdChallenge, secondChallenge]); } - challengeRepository.findFlashCompatible.resolves([firstChallenge, secondChallenge, thirdChallenge]); + challengeRepository.findActiveFlashCompatible.resolves([firstChallenge, secondChallenge, thirdChallenge]); pickChallenge .withArgs({