Skip to content

Commit

Permalink
refactor(api): use current flash algo config in simulators
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrecoin authored Nov 21, 2024
1 parent 10b3ec6 commit fcd8150
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ export async function simulateFlashAssessmentScenario({
variationPercent,
challengeRepository,
flashAlgorithmService,
sharedFlashAlgorithmConfigurationRepository,
}) {
const challenges = await challengeRepository.findActiveFlashCompatible({ locale });

const enablePassageByAllCompetencesValueInProduction = true;
const configurationUsedInProduction = await sharedFlashAlgorithmConfigurationRepository.getMostRecent();

const flashAssessmentAlgorithm = new FlashAssessmentAlgorithm({
flashAlgorithmImplementation: flashAlgorithmService,
configuration: new FlashAssessmentAlgorithmConfiguration({
limitToOneQuestionPerTube,
minimumEstimatedSuccessRateRanges,
enablePassageByAllCompetences: enablePassageByAllCompetencesValueInProduction,
enablePassageByAllCompetences: configurationUsedInProduction.enablePassageByAllCompetences,
variationPercent,
variationPercentUntil: undefined,
doubleMeasuresUntil: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ describe('Unit | UseCase | simulate-flash-assessment-scenario', function () {
context('when no initial capacity is provided', function () {
it('should return an array of capacity, challenge, reward and error rate for each answer', async function () {
// given
const { challengeRepository, pickChallenge, pickAnswerStatus, flashAlgorithmService } = prepareStubs();
const {
challengeRepository,
sharedFlashAlgorithmConfigurationRepository,
pickChallenge,
pickAnswerStatus,
flashAlgorithmService,
} = prepareStubs();

// when
const result = await simulateFlashAssessmentScenario({
Expand All @@ -26,6 +32,7 @@ describe('Unit | UseCase | simulate-flash-assessment-scenario', function () {
pickChallenge,
pickAnswerStatus,
flashAlgorithmService,
sharedFlashAlgorithmConfigurationRepository,
});

// then
Expand All @@ -45,10 +52,16 @@ describe('Unit | UseCase | simulate-flash-assessment-scenario', function () {
// given
const initialCapacity = 7;

const { challengeRepository, firstChallenge, pickChallenge, pickAnswerStatus, flashAlgorithmService } =
prepareStubs({
initialCapacity,
});
const {
challengeRepository,
sharedFlashAlgorithmConfigurationRepository,
firstChallenge,
pickChallenge,
pickAnswerStatus,
flashAlgorithmService,
} = prepareStubs({
initialCapacity,
});

flashAlgorithmService.getReward
.withArgs({
Expand All @@ -62,6 +75,7 @@ describe('Unit | UseCase | simulate-flash-assessment-scenario', function () {
const result = await simulateFlashAssessmentScenario({
stopAtChallenge: 3,
challengeRepository,
sharedFlashAlgorithmConfigurationRepository,
locale,
pickChallenge,
pickAnswerStatus,
Expand Down Expand Up @@ -89,6 +103,7 @@ describe('Unit | UseCase | simulate-flash-assessment-scenario', function () {

const {
challengeRepository,
sharedFlashAlgorithmConfigurationRepository,
pickChallenge,
pickAnswerStatus,
flashAlgorithmService: baseFlashAlgorithmService,
Expand Down Expand Up @@ -128,6 +143,7 @@ describe('Unit | UseCase | simulate-flash-assessment-scenario', function () {
const result = await simulateFlashAssessmentScenario({
stopAtChallenge: 3,
challengeRepository,
sharedFlashAlgorithmConfigurationRepository,
locale,
pickChallenge,
pickAnswerStatus,
Expand Down Expand Up @@ -159,14 +175,21 @@ describe('Unit | UseCase | simulate-flash-assessment-scenario', function () {
}),
];

const { challengeRepository, pickChallenge, pickAnswerStatus, flashAlgorithmService } = prepareStubs({
const {
challengeRepository,
sharedFlashAlgorithmConfigurationRepository,
pickChallenge,
pickAnswerStatus,
flashAlgorithmService,
} = prepareStubs({
minimalSuccessRate: 0.8,
});

// when
const result = await simulateFlashAssessmentScenario({
stopAtChallenge: 3,
challengeRepository,
sharedFlashAlgorithmConfigurationRepository,
locale,
pickChallenge,
pickAnswerStatus,
Expand Down Expand Up @@ -196,6 +219,10 @@ describe('Unit | UseCase | simulate-flash-assessment-scenario', function () {
const challengeRepository = {
findActiveFlashCompatible: sinon.stub(),
};
const sharedFlashAlgorithmConfigurationRepository = {
getMostRecent: sinon.stub(),
};
sharedFlashAlgorithmConfigurationRepository.getMostRecent.resolves({ enablePassageByAllCompetences: true });
challengeRepository.findActiveFlashCompatible.resolves([challenge]);

const pickChallenge = sinon.stub();
Expand Down Expand Up @@ -238,6 +265,7 @@ describe('Unit | UseCase | simulate-flash-assessment-scenario', function () {
// when
const error = await catchErr(simulateFlashAssessmentScenario)({
challengeRepository,
sharedFlashAlgorithmConfigurationRepository,
locale,
pickChallenge,
pickAnswerStatus,
Expand Down Expand Up @@ -287,6 +315,11 @@ function prepareStubs({
const challengeRepository = {
findActiveFlashCompatible: sinon.stub(),
};

const sharedFlashAlgorithmConfigurationRepository = {
getMostRecent: sinon.stub(),
};

const pickChallenge = sinon.stub();
const pickAnswerStatus = sinon.stub();
const flashAlgorithmService = {
Expand All @@ -304,6 +337,8 @@ function prepareStubs({
),
);

sharedFlashAlgorithmConfigurationRepository.getMostRecent.resolves({ enablePassageByAllCompetences: true });

flashAlgorithmService.getCapacityAndErrorRate
.withArgs({
allAnswers: [],
Expand Down Expand Up @@ -418,6 +453,7 @@ function prepareStubs({
pickChallenge,
pickAnswerStatus,
challengeRepository,
sharedFlashAlgorithmConfigurationRepository,
flashAlgorithmService,
firstChallenge,
allChallenges,
Expand Down

0 comments on commit fcd8150

Please sign in to comment.