Skip to content

Commit

Permalink
[TECH] Extraction d'une erreur spécifique pour pix 1d : `MissionNotFo…
Browse files Browse the repository at this point in the history
…undError`

 #8066
  • Loading branch information
pix-service-auto-merge authored Feb 20, 2024
2 parents e378c2d + 7edbf4f commit 8367b08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion api/src/school/domain/school-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ class SchoolNotFoundError extends DomainError {
}
}

export { ActivityNotFoundError, SchoolNotFoundError };
class MissionNotFoundError extends DomainError {
constructor(missionId) {
super(`Il n'existe pas de mission ayant pour id ${missionId}`);
this.code = missionId;
}
}

export { ActivityNotFoundError, SchoolNotFoundError, MissionNotFoundError };
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Mission } from '../../domain/models/Mission.js';
import { missionDatasource } from '../datasources/learning-content/mission-datasource.js';
import { getTranslatedKey } from '../../../../lib/domain/services/get-translated-text.js';
import { LOCALE } from '../../../shared/domain/constants.js';
import { NotFoundError } from '../../../../lib/domain/errors.js';
import { MissionNotFoundError } from '../../domain/school-errors.js';

const { FRENCH_FRANCE } = LOCALE;

Expand All @@ -27,7 +27,7 @@ async function get(id, locale = { locale: FRENCH_FRANCE }) {
const missionData = await missionDatasource.get(id);
return _toDomain(missionData, locale);
} catch (error) {
throw new NotFoundError(`Il n'existe pas de mission ayant pour id ${id}`);
throw new MissionNotFoundError(id);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, mockLearningContent, catchErr } from '../../../../test-helper.js';
import * as missionRepository from '../../../../../src/school/infrastructure/repositories/mission-repository.js';
import { Mission } from '../../../../../src/school/domain/models/Mission.js';
import { NotFoundError } from '../../../../../lib/domain/errors.js';
import { MissionNotFoundError } from '../../../../../src/school/domain/school-errors.js';
describe('Integration | Repository | mission-repository', function () {
describe('#get', function () {
context('when there is a mission for the given id', function () {
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('Integration | Repository | mission-repository', function () {
const error = await catchErr(missionRepository.get)(missionId);

// then
expect(error).to.be.instanceOf(NotFoundError);
expect(error).to.be.instanceOf(MissionNotFoundError);
expect(error.message).to.deep.equal(`Il n'existe pas de mission ayant pour id ${missionId}`);
});
});
Expand Down

0 comments on commit 8367b08

Please sign in to comment.