Skip to content

Commit

Permalink
refactor(api): rename accessibility1 and 2 for better clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
HEYGUL authored Sep 23, 2024
1 parent a95d6b5 commit e84feee
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 52 deletions.
16 changes: 8 additions & 8 deletions api/src/shared/domain/models/Challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class Challenge {
* @param successProbabilityThreshold
* @param shuffled
* @param alternativeVersion
* @param accessibility1
* @param accessibility2
* @param blindnessCompatibility
* @param colorBlindnessCompatibility
*/
constructor({
id,
Expand Down Expand Up @@ -87,8 +87,8 @@ class Challenge {
responsive,
shuffled,
alternativeVersion,
accessibility1,
accessibility2,
blindnessCompatibility,
colorBlindnessCompatibility,
} = {}) {
this.id = id;
this.answer = answer;
Expand Down Expand Up @@ -119,8 +119,8 @@ class Challenge {
this.successProbabilityThreshold = successProbabilityThreshold;
this.shuffled = shuffled;
this.alternativeVersion = alternativeVersion;
this.accessibility1 = accessibility1;
this.accessibility2 = accessibility2;
this.blindnessCompatibility = blindnessCompatibility;
this.colorBlindnessCompatibility = colorBlindnessCompatibility;
}

isTimed() {
Expand Down Expand Up @@ -161,8 +161,8 @@ class Challenge {

get isAccessible() {
return (
(this.accessibility1 === Accessibility.OK || this.accessibility1 === Accessibility.RAS) &&
(this.accessibility2 === Accessibility.OK || this.accessibility2 === Accessibility.RAS)
(this.blindnessCompatibility === Accessibility.OK || this.blindnessCompatibility === Accessibility.RAS) &&
(this.colorBlindnessCompatibility === Accessibility.OK || this.colorBlindnessCompatibility === Accessibility.RAS)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function _toDomain({ challengeDataObject, skillDataObject, successProbabilityThr
shuffled: challengeDataObject.shuffled,
successProbabilityThreshold,
alternativeVersion: challengeDataObject.alternativeVersion,
accessibility1: challengeDataObject.accessibility1,
accessibility2: challengeDataObject.accessibility2,
blindnessCompatibility: challengeDataObject.accessibility1,
colorBlindnessCompatibility: challengeDataObject.accessibility2,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Unit | Domain | Use Cases | get-next-challenge', function () {
it('should save the returned next challenge', async function () {
// given
const nextChallengeToAnswer = domainBuilder.buildChallenge({
accessibility1: 'KO',
blindnessCompatibility: 'KO',
});
const v3CertificationCourse = domainBuilder.buildCertificationCourse({
version: CERTIFICATION_VERSIONS.V3,
Expand Down Expand Up @@ -143,19 +143,19 @@ describe('Unit | Domain | Use Cases | get-next-challenge', function () {
it('should only pick among challenges with no accessibilities issues', async function () {
// given
const nextChallengeToAnswer = domainBuilder.buildChallenge({
accessibility1: 'RAS',
accessibility2: 'OK',
blindnessCompatibility: 'RAS',
colorBlindnessCompatibility: 'OK',
});
const accessibleChallenge = domainBuilder.buildChallenge({
accessibility1: 'OK',
accessibility2: 'RAS',
blindnessCompatibility: 'OK',
colorBlindnessCompatibility: 'RAS',
});
const allChallenges = [
nextChallengeToAnswer,
accessibleChallenge,
domainBuilder.buildChallenge({
accessibility1: 'autre chose',
accessibility2: 'OK',
blindnessCompatibility: 'autre chose',
colorBlindnessCompatibility: 'OK',
}),
];
const v3CertificationCourse = domainBuilder.buildCertificationCourse({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('Integration | Repository | challenge-repository', function () {
...challenge,
focused: challenge.focusable,
skill: domainBuilder.buildSkill({ ...skill, difficulty: skill.level }),
blindnessCompatibility: challenge.accessibility1,
colorBlindnessCompatibility: challenge.accessibility2,
});

// when
Expand Down Expand Up @@ -89,6 +91,8 @@ describe('Integration | Repository | challenge-repository', function () {
webComponentProps: { prop1: 'value1', prop2: 'value2' },
focused: challenge.focusable,
skill: domainBuilder.buildSkill({ ...skill, difficulty: skill.level }),
blindnessCompatibility: challenge.accessibility1,
colorBlindnessCompatibility: challenge.accessibility2,
});

// when
Expand All @@ -113,7 +117,16 @@ describe('Integration | Repository | challenge-repository', function () {

const learningContent = {
skills: [{ ...skill, status: 'actif' }],
challenges: [{ ...challenge, skillId: 'recSkill1', alpha: 1, delta: 0 }],
challenges: [
{
...challenge,
skillId: 'recSkill1',
alpha: 1,
delta: 0,
blindnessCompatibility: challenge.accessibility1,
colorBlindnessCompatibility: challenge.accessibility2,
},
],
};

mockLearningContent(learningContent);
Expand Down
16 changes: 8 additions & 8 deletions api/tests/tooling/domain-builder/factory/build-challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const buildChallenge = function ({
focused = false,
shuffled = false,
alternativeVersion = undefined,
accessibility1 = 'OK',
accessibility2 = 'RAS',
blindnessCompatibility = 'OK',
colorBlindnessCompatibility = 'RAS',
// includes
answer,
validator = new Validator(),
Expand Down Expand Up @@ -61,8 +61,8 @@ const buildChallenge = function ({
illustrationAlt,
shuffled,
alternativeVersion,
accessibility1,
accessibility2,
blindnessCompatibility,
colorBlindnessCompatibility,
// includes
answer,
validator,
Expand Down Expand Up @@ -97,8 +97,8 @@ const buildChallengeWithWebComponent = function ({
focused = false,
shuffled = false,
alternativeVersion = undefined,
accessibility1,
accessibility2,
blindnessCompatibility,
colorBlindnessCompatibility,
// includes
answer,
validator = new Validator(),
Expand Down Expand Up @@ -131,8 +131,8 @@ const buildChallengeWithWebComponent = function ({
illustrationAlt,
shuffled,
alternativeVersion,
accessibility1,
accessibility2,
blindnessCompatibility,
colorBlindnessCompatibility,
// includes
answer,
validator,
Expand Down
55 changes: 29 additions & 26 deletions api/tests/unit/domain/models/Challenge_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ describe('Unit | Domain | Models | Challenge', function () {
responsive: 'Smartphone',
shuffled: false,
alternativeVersion: 1,
accessibility1: 'OK',
accessibility2: 'KO',
blindnessCompatibility: 'OK',
colorBlindnessCompatibility: 'KO',
};

const expectedChallengeDataObject = {
Expand Down Expand Up @@ -80,8 +80,8 @@ describe('Unit | Domain | Models | Challenge', function () {
responsive: 'Smartphone',
shuffled: false,
alternativeVersion: 1,
accessibility1: 'OK',
accessibility2: 'KO',
blindnessCompatibility: 'OK',
colorBlindnessCompatibility: 'KO',
};

// when
Expand Down Expand Up @@ -126,8 +126,8 @@ describe('Unit | Domain | Models | Challenge', function () {
responsive: 'Smartphone',
shuffled: false,
alternativeVersion: 1,
accessibility1: 'OK',
accessibility2: 'KO',
blindnessCompatibility: 'OK',
colorBlindnessCompatibility: 'KO',
};

const expectedChallengeDataObject = {
Expand Down Expand Up @@ -162,8 +162,8 @@ describe('Unit | Domain | Models | Challenge', function () {
responsive: 'Smartphone',
shuffled: false,
alternativeVersion: 1,
accessibility1: 'OK',
accessibility2: 'KO',
blindnessCompatibility: 'OK',
colorBlindnessCompatibility: 'KO',
};

// when
Expand Down Expand Up @@ -342,25 +342,28 @@ describe('Unit | Domain | Models | Challenge', function () {
describe('#isAccessible', function () {
/* eslint-disable mocha/no-setup-in-describe */
[
{ accessibility1: Accessibility.OK, accessibility2: Accessibility.OK, isAccessible: true },
{ accessibility1: Accessibility.OK, accessibility2: Accessibility.RAS, isAccessible: true },
{ accessibility1: Accessibility.RAS, accessibility2: Accessibility.OK, isAccessible: true },
{ accessibility1: Accessibility.RAS, accessibility2: Accessibility.RAS, isAccessible: true },
{ accessibility1: Accessibility.OK, accessibility2: 'KO', isAccessible: false },
{ accessibility1: Accessibility.OK, accessibility2: 'autre chose', isAccessible: false },
{ accessibility1: 'autre chose', accessibility2: Accessibility.OK, isAccessible: false },
{ accessibility1: 'KO', accessibility2: Accessibility.RAS, isAccessible: false },
{ blindnessCompatibility: Accessibility.OK, colorBlindnessCompatibility: Accessibility.OK, isAccessible: true },
{ blindnessCompatibility: Accessibility.OK, colorBlindnessCompatibility: Accessibility.RAS, isAccessible: true },
{ blindnessCompatibility: Accessibility.RAS, colorBlindnessCompatibility: Accessibility.OK, isAccessible: true },
{ blindnessCompatibility: Accessibility.RAS, colorBlindnessCompatibility: Accessibility.RAS, isAccessible: true },
{ blindnessCompatibility: Accessibility.OK, colorBlindnessCompatibility: 'KO', isAccessible: false },
{ blindnessCompatibility: Accessibility.OK, colorBlindnessCompatibility: 'autre chose', isAccessible: false },
{ blindnessCompatibility: 'autre chose', colorBlindnessCompatibility: Accessibility.OK, isAccessible: false },
{ blindnessCompatibility: 'KO', colorBlindnessCompatibility: Accessibility.RAS, isAccessible: false },
/* eslint-enable mocha/no-setup-in-describe */
].forEach(({ accessibility1, accessibility2, isAccessible }) => {
context(`when accessibility1 is ${accessibility1} and accessibility2 is ${accessibility2}`, function () {
it(`returns ${isAccessible}`, function () {
// given
const challenge = domainBuilder.buildChallenge({ accessibility1, accessibility2 });

// when then
expect(challenge.isAccessible).to.equal(isAccessible);
});
});
].forEach(({ blindnessCompatibility, colorBlindnessCompatibility, isAccessible }) => {
context(
`when blindnessCompatibility is ${blindnessCompatibility} and colorBlindnessCompatibility is ${colorBlindnessCompatibility}`,
function () {
it(`returns ${isAccessible}`, function () {
// given
const challenge = domainBuilder.buildChallenge({ blindnessCompatibility, colorBlindnessCompatibility });

// when then
expect(challenge.isAccessible).to.equal(isAccessible);
});
},
);
});
});
});

0 comments on commit e84feee

Please sign in to comment.