From 2ffb8604bfbc2093ff0461daaf52310f38d9aa7a Mon Sep 17 00:00:00 2001 From: P-Jeremy Date: Mon, 25 Nov 2024 15:08:55 +0100 Subject: [PATCH] :sparkles: api: add accessibilityAdjustmentNeeded param to #findActiveFlashCompatible repo method Co-authored-by: Yannick Francois --- .../repositories/challenge-repository.js | 14 ++++- .../repositories/challenge-repository_test.js | 53 ++++++++++++++++--- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/api/src/shared/infrastructure/repositories/challenge-repository.js b/api/src/shared/infrastructure/repositories/challenge-repository.js index 55465aa6958..dded7afcebd 100644 --- a/api/src/shared/infrastructure/repositories/challenge-repository.js +++ b/api/src/shared/infrastructure/repositories/challenge-repository.js @@ -3,6 +3,7 @@ import _ from 'lodash'; import { httpAgent } from '../../../../lib/infrastructure/http/http-agent.js'; import { config } from '../../config.js'; import { NotFoundError } from '../../domain/errors.js'; +import { Accessibility } from '../../domain/models/Challenge.js'; import { Challenge } from '../../domain/models/index.js'; import * as solutionAdapter from '../../infrastructure/adapters/solution-adapter.js'; import * as skillAdapter from '../adapters/skill-adapter.js'; @@ -88,9 +89,20 @@ const findOperativeBySkills = async function (skills, locale) { const findActiveFlashCompatible = async function ({ locale, successProbabilityThreshold = config.features.successProbabilityThreshold, + accessibilityAdjustmentNeeded = false, } = {}) { _assertLocaleIsDefined(locale); - const challengeDataObjects = await challengeDatasource.findActiveFlashCompatible(locale); + let challengeDataObjects = await challengeDatasource.findActiveFlashCompatible(locale); + if (accessibilityAdjustmentNeeded) { + challengeDataObjects = challengeDataObjects.filter((challengeDataObject) => { + return ( + (challengeDataObject.accessibility1 === Accessibility.OK || + challengeDataObject.accessibility1 === Accessibility.RAS) && + (challengeDataObject.accessibility2 === Accessibility.OK || + challengeDataObject.accessibility2 === Accessibility.RAS) + ); + }); + } const activeSkills = await skillDatasource.findActive(); return _toDomainCollection({ challengeDataObjects, skills: activeSkills, successProbabilityThreshold }); }; 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 9c9d08b3d38..52b68fbe223 100644 --- a/api/tests/shared/integration/infrastructure/repositories/challenge-repository_test.js +++ b/api/tests/shared/integration/infrastructure/repositories/challenge-repository_test.js @@ -512,6 +512,7 @@ describe('Integration | Repository | challenge-repository', function () { status: 'périmé', locales: ['nl'], }); + const learningContent = { skills: [{ ...skill, status: 'actif', level: skill.difficulty }], challenges: [ @@ -555,7 +556,6 @@ describe('Integration | Repository | challenge-repository', function () { expect(actualChallenges[1]).to.deep.contain({ status: 'archivé', }); - expect(actualChallenges[2]).to.deep.contain({ status: 'périmé', }); @@ -586,12 +586,33 @@ describe('Integration | Repository | challenge-repository', function () { status: 'périmé', locales, }); + const nonAccessibleChallenge = domainBuilder.buildChallenge({ + id: 'nonAccessibleChallenge', + skill, + status: 'validé', + locales, + }); const learningContent = { skills: [{ ...skill, status: 'actif', level: skill.difficulty }], challenges: [ - { ...activeChallenge, skillId: 'recSkill1', alpha: 3.57, delta: -8.99 }, - { ...archivedChallenge, skillId: 'recSkill1' }, - { ...outdatedChallenge, skillId: 'recSkill1' }, + { + ...activeChallenge, + accessibility1: 'OK', + accessibility2: 'OK', + skillId: 'recSkill1', + alpha: 3.57, + delta: -8.99, + }, + { ...archivedChallenge, accessibility1: 'OK', accessibility2: 'OK', skillId: 'recSkill1' }, + { ...outdatedChallenge, accessibility1: 'OK', accessibility2: 'OK', skillId: 'recSkill1' }, + { + ...nonAccessibleChallenge, + accessibility1: 'KO', + accessibility2: 'OK', + skillId: 'recSkill1', + alpha: 3.57, + delta: -8.99, + }, ], }; await mockLearningContent(learningContent); @@ -609,7 +630,7 @@ describe('Integration | Repository | challenge-repository', function () { }); // then - expect(actualChallenges).to.have.lengthOf(1); + expect(actualChallenges).to.have.lengthOf(2); expect(actualChallenges[0]).to.be.instanceOf(Challenge); expect(actualChallenges[0]).to.deep.contain({ id: 'activeChallenge', @@ -635,10 +656,30 @@ describe('Integration | Repository | challenge-repository', function () { }); // then - expect(actualChallenges).to.have.lengthOf(1); + expect(actualChallenges).to.have.lengthOf(2); expect(actualChallenges[0]).to.be.instanceOf(Challenge); expect(actualChallenges[0].minimumCapability).to.equal(-8.682265465359073); }); + + context('when requesting only accessible challenges', function () { + it('should return all accessible flash compatible challenges with skills', async function () { + // given + const successProbabilityThreshold = 0.95; + + // when + const actualChallenges = await challengeRepository.findActiveFlashCompatible({ + locale: 'fr-fr', + successProbabilityThreshold, + accessibilityAdjustmentNeeded: true, + }); + + // then + expect(actualChallenges).to.have.lengthOf(1); + expect(actualChallenges[0]).to.deep.contain({ + status: 'validé', + }); + }); + }); }); describe('#findValidatedBySkillId', function () {