Skip to content

Commit

Permalink
[BUGFIX] Ne pas retourner une erreur 500 lors de la vérification de l…
Browse files Browse the repository at this point in the history
…'éligibilité d'un utilisateur sans badges (PIX-14764).

 #10378
  • Loading branch information
pix-service-auto-merge authored Oct 22, 2024
2 parents ed30727 + 5c317a4 commit 5b2b938
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function verifyCandidateSubscriptions({
certificationBadgesService,
});

if (_isSubscribedUserBadgeOutDated(subscribedHighestBadgeAcquisition)) {
if (!subscribedHighestBadgeAcquisition || _isSubscribedUserBadgeOutDated(subscribedHighestBadgeAcquisition)) {
throw new CertificationCandidateEligibilityError();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,47 @@ describe('Certification | Enrolment | Unit | Domain | UseCase | verify-candidate
expect(error).to.be.instanceOf(CertificationCandidateEligibilityError);
});
});

context('when there is no acquired badges', function () {
it('should throw CertificationCandidateEligibilityError', async function () {
// given
const certificationCandidateId = 456;
const complementaryCertificationId = 789;

const candidate = domainBuilder.certification.enrolment.buildCandidate({
id: certificationCandidateId,
userId: 1234,
subscriptions: [
domainBuilder.certification.enrolment.buildComplementarySubscription({
certificationCandidateId,
complementaryCertificationId,
}),
],
});

dependencies.pixCertificationRepository.findByUserId.resolves([
domainBuilder.certification.enrolment.buildPixCertification({
pixScore: 250,
status: AssessmentResult.status.VALIDATED,
isCancelled: false,
isRejectedForFraud: false,
}),
]);

dependencies.certificationBadgesService.findLatestBadgeAcquisitions.resolves([]);

// when
const error = await catchErr(verifyCandidateSubscriptions)({
userId: candidate.userId,
candidate,
limitDate: Date.now(),
...dependencies,
});

//then
expect(error).to.be.instanceOf(CertificationCandidateEligibilityError);
});
});
context('when score is below lower level', function () {
it('should throw CertificationCandidateEligibilityError', async function () {
// given
Expand Down

0 comments on commit 5b2b938

Please sign in to comment.