Skip to content

Commit

Permalink
✨ api: add accessibilityAdjustmentNeeded param to #findActiveFlashCom…
Browse files Browse the repository at this point in the history
…patible repo method

Co-authored-by: Yannick Francois <[email protected]>
  • Loading branch information
P-Jeremy and yaf authored Nov 26, 2024
1 parent 9600327 commit 2ffb860
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 });
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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é',
});
Expand Down Expand Up @@ -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);
Expand All @@ -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',
Expand All @@ -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 () {
Expand Down

0 comments on commit 2ffb860

Please sign in to comment.