Skip to content

Commit

Permalink
Use correct repo in get-next-challenge-for-v3-certification
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Jeremy committed Sep 20, 2024
1 parent 483e73a commit 0bf3e02
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const debugGetNextChallengeForV3Certification = Debug('pix:certif:v3:get-next-ch
* @param {FlashAlgorithmConfigurationRepository} params.flashAlgorithmConfigurationRepository
* @param {FlashAlgorithmService} params.flashAlgorithmService
* @param {PickChallengeService} params.pickChallengeService
* @param {CertificationCandidateForSupervisingRepository} params.certificationCandidateForSupervisingRepository
* @param {CertificationCandidateForSupervising.id} params.certificationCandidateId
* @param {CertificationCandidateRepository} params.certificationCandidateRepository
* @param {CertificationCandidate.id} params.certificationCandidateId
*/
const getNextChallengeForV3Certification = async function ({
assessment,
Expand All @@ -41,8 +41,7 @@ const getNextChallengeForV3Certification = async function ({
flashAlgorithmService,
locale,
pickChallengeService,
certificationCandidateForSupervisingRepository,
certificationCandidateId,
certificationCandidateRepository,
}) {
const certificationCourse = await certificationCourseRepository.get({ id: assessment.certificationCourseId });

Expand Down Expand Up @@ -86,7 +85,7 @@ const getNextChallengeForV3Certification = async function ({
challenges,
});

const candidate = await certificationCandidateForSupervisingRepository.get({ certificationCandidateId });
const candidate = await certificationCandidateRepository.findByAssessmentId({ assessmentId: assessment.id });
const challengesForCandidate = candidate.accessibilityAdjustmentNeeded
? challengesWithoutSkillsWithAValidatedLiveAlert.filter((challenge) => challenge.isAccessible)
: challengesWithoutSkillsWithAValidatedLiveAlert;
Expand Down
2 changes: 2 additions & 0 deletions api/src/certification/evaluation/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import {
sessionRepositories,
sharedCompetenceMarkRepository,
} from '../../../session-management/infrastructure/repositories/index.js';
import * as certificationCandidateRepository from '../../infrastructure/repositories/certification-candidate-repository.js';

const dependencies = {
...sessionRepositories,
certificationCandidateRepository,
assessmentRepository,
assessmentResultRepository,
answerRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { knex } from '../../../../../db/knex-database-connection.js';
import { CertificationCandidateNotFoundError } from '../../../../shared/domain/errors.js';
import { CertificationCandidate } from '../../../../shared/domain/models/CertificationCandidate.js';
import { Candidate } from '../../../enrolment/domain/models/Candidate.js';

const findByAssessmentId = async function ({ assessmentId }) {
const result = await knex('certification-candidates')
Expand All @@ -14,7 +14,7 @@ const findByAssessmentId = async function ({ assessmentId }) {
throw new CertificationCandidateNotFoundError();
}

return new CertificationCandidate(result);
return new Candidate(result);
};

export { findByAssessmentId };
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Integration | Repository | certification candidate', function () {

// then
expect(result).to.deep.equal(
domainBuilder.buildCertificationCandidate({
domainBuilder.certification.enrolment.buildCandidate({
...candidate,
subscriptions: [],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-v3-certification',
pickChallengeService,
flashAlgorithmService,
flashAlgorithmConfigurationRepository,
certificationCandidateForSupervisingRepository;
certificationCandidateRepository;

let flashAlgorithmConfiguration;
let certificationCandidateId;
let assessment;

beforeEach(function () {
flashAlgorithmConfigurationRepository = {
Expand Down Expand Up @@ -47,15 +48,16 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-v3-certification',
getPossibleNextChallenges: sinon.stub(),
getCapacityAndErrorRate: sinon.stub(),
};
certificationCandidateForSupervisingRepository = {
get: sinon.stub(),
certificationCandidateRepository = {
findByAssessmentId: sinon.stub(),
};
assessment = domainBuilder.buildAssessment();
const candidate = domainBuilder.buildCertificationCandidateForSupervising({
accessibilityAdjustmentNeeded: false,
});
certificationCandidateId = candidate.id;

certificationCandidateForSupervisingRepository.get.withArgs({ certificationCandidateId }).resolves(candidate);
certificationCandidateRepository.findByAssessmentId.withArgs({ assessmentId: assessment.id }).resolves(candidate);

flashAlgorithmConfiguration = domainBuilder.buildFlashAlgorithmConfiguration();
});
Expand All @@ -69,7 +71,6 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-v3-certification',
const v3CertificationCourse = domainBuilder.buildCertificationCourse({
version: CERTIFICATION_VERSIONS.V3,
});
const assessment = domainBuilder.buildAssessment();
const locale = 'fr-FR';

flashAlgorithmConfigurationRepository.getMostRecentBeforeDate
Expand Down Expand Up @@ -131,8 +132,7 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-v3-certification',
flashAlgorithmService,
locale,
pickChallengeService,
certificationCandidateForSupervisingRepository,
certificationCandidateId,
certificationCandidateRepository,
});

// then
Expand Down Expand Up @@ -215,8 +215,8 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-v3-certification',
accessibilityAdjustmentNeeded: true,
});

certificationCandidateForSupervisingRepository.get
.withArgs({ certificationCandidateId: candidateNeedingAccessibilityAdjustment.id })
certificationCandidateRepository.findByAssessmentId
.withArgs({ assessmentId: assessment.id })
.resolves(candidateNeedingAccessibilityAdjustment);

// when
Expand All @@ -231,8 +231,7 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-v3-certification',
flashAlgorithmService,
locale,
pickChallengeService,
certificationCandidateId: candidateNeedingAccessibilityAdjustment.id,
certificationCandidateForSupervisingRepository,
certificationCandidateRepository,
});

// then
Expand Down Expand Up @@ -283,8 +282,7 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-v3-certification',
flashAlgorithmService,
locale,
pickChallengeService,
certificationCandidateForSupervisingRepository,
certificationCandidateId,
certificationCandidateRepository,
});

// then
Expand Down Expand Up @@ -376,8 +374,7 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-v3-certification',
flashAlgorithmService,
locale,
pickChallengeService,
certificationCandidateForSupervisingRepository,
certificationCandidateId,
certificationCandidateRepository,
});

// then
Expand Down Expand Up @@ -475,8 +472,7 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-v3-certification',
flashAlgorithmService,
locale,
pickChallengeService,
certificationCandidateForSupervisingRepository,
certificationCandidateId,
certificationCandidateRepository,
});

// then
Expand Down Expand Up @@ -534,7 +530,7 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-v3-certification',
flashAlgorithmService,
locale,
pickChallengeService,
certificationCandidateForSupervisingRepository,
certificationCandidateRepository,
certificationCandidateId,
});

Expand Down Expand Up @@ -640,8 +636,7 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-v3-certification',
flashAlgorithmService,
locale,
pickChallengeService,
certificationCandidateForSupervisingRepository,
certificationCandidateId,
certificationCandidateRepository,
});

// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ describe('Acceptance | API | assessment-controller-get-next-challenge-for-certif

beforeEach(async function () {
const user = databaseBuilder.factory.buildUser({ id: userId });
databaseBuilder.factory.buildCertificationCandidate(user);
const certificationCenterId = databaseBuilder.factory.buildCertificationCenter({ isV3Pilot: true }).id;
const sessionId = databaseBuilder.factory.buildSession({
certificationCenterId,
Expand All @@ -97,6 +96,7 @@ describe('Acceptance | API | assessment-controller-get-next-challenge-for-certif
userId,
sessionId,
}).id;
databaseBuilder.factory.buildCertificationCandidate({ ...user, userId: user.id, sessionId });
databaseBuilder.factory.buildAssessment({
id: assessmentId,
type: Assessment.types.CERTIFICATION,
Expand Down

0 comments on commit 0bf3e02

Please sign in to comment.