Skip to content

Commit

Permalink
refactor(api): remove useObsoleteChallenges parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrecoin committed Nov 15, 2024
1 parent ac356e9 commit 7cea5f9
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ async function simulateFlashAssessmentScenario(
stopAtChallenge,
initialCapacity,
numberOfIterations = 1,
useObsoleteChallenges,
challengePickProbability,
challengesBetweenSameCompetence,
limitToOneQuestionPerTube,
Expand Down Expand Up @@ -58,7 +57,6 @@ async function simulateFlashAssessmentScenario(
locale,
stopAtChallenge,
initialCapacity,
useObsoleteChallenges,
challengesBetweenSameCompetence,
limitToOneQuestionPerTube,
minimumEstimatedSuccessRateRanges,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export async function simulateFlashAssessmentScenario({
pickAnswerStatus,
stopAtChallenge,
initialCapacity,
useObsoleteChallenges,
challengesBetweenSameCompetence = 0,
limitToOneQuestionPerTube = true,
minimumEstimatedSuccessRateRanges = [],
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -132,7 +125,6 @@ export async function getManyTypes(ids) {

export {
findActiveFlashCompatible,
findFlashCompatible,
findFlashCompatibleWithoutLocale,
findOperative,
findOperativeBySkills,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -430,7 +430,7 @@ function prepareStubs({
.returns([thirdChallenge, secondChallenge]);
}

challengeRepository.findFlashCompatible.resolves([firstChallenge, secondChallenge, thirdChallenge]);
challengeRepository.findActiveFlashCompatible.resolves([firstChallenge, secondChallenge, thirdChallenge]);

pickChallenge
.withArgs({
Expand Down

0 comments on commit 7cea5f9

Please sign in to comment.