Skip to content

Commit

Permalink
[BUGFIX] Ne plus retourner de 500 lors de la consultation de learner …
Browse files Browse the repository at this point in the history
…d'organization ayant l'import à format (Pix-15610)

 #10744
  • Loading branch information
pix-service-auto-merge authored Dec 9, 2024
2 parents 81afa8f + b7d251c commit e7761ff
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ class OrganizationLearnerForAdmin {
}

updateDivisionAndBirthdate({ additionalInformations, additionalColumns }) {
const dateOfBirthColumn = additionalColumns.find((column) => column.name === IMPORT_KEY_FIELD.COMMON_BIRTHDATE);
if (dateOfBirthColumn) {
this.birthdate = additionalInformations[dateOfBirthColumn.key];
}
const divisionColumn = additionalColumns.find((column) => column.name === IMPORT_KEY_FIELD.COMMON_DIVISION);
if (divisionColumn) {
this.division = additionalInformations[divisionColumn.key];
if (additionalInformations) {
const dateOfBirthColumn = additionalColumns.find((column) => column.name === IMPORT_KEY_FIELD.COMMON_BIRTHDATE);
if (dateOfBirthColumn) {
this.birthdate = additionalInformations[dateOfBirthColumn.key];
}
const divisionColumn = additionalColumns.find((column) => column.name === IMPORT_KEY_FIELD.COMMON_DIVISION);
if (divisionColumn) {
this.division = additionalInformations[divisionColumn.key];
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,41 @@ describe('Unit | Domain | Read-models | OrganizationLearnerForAdmin', function (
expect(() => new OrganizationLearnerForAdmin(validArguments)).not.to.throw(ObjectValidationError);
});

it('should overide birthdate and division if additionalColumns and additionalInfos are given', function () {
const learner = new OrganizationLearnerForAdmin({
...validArguments,
additionalColumns: [
{
name: IMPORT_KEY_FIELD.COMMON_BIRTHDATE,
key: 'dateofbirth',
describe('additionalColumns', function () {
it('should not throw when addtionalInformations is not defined', function () {
const learner = new OrganizationLearnerForAdmin({
...validArguments,
additionalColumns: [
{
name: IMPORT_KEY_FIELD.COMMON_BIRTHDATE,
key: 'dateofbirth',
},
{ name: IMPORT_KEY_FIELD.COMMON_DIVISION, key: 'groupe' },
],
additionalInformations: null,
});
expect(learner.division).to.equal('3A');
expect(learner.birthdate).to.deep.equal('2000-10-15');
});

it('should overide birthdate and division if additionalColumns and additionalInfos are given', function () {
const learner = new OrganizationLearnerForAdmin({
...validArguments,
additionalColumns: [
{
name: IMPORT_KEY_FIELD.COMMON_BIRTHDATE,
key: 'dateofbirth',
},
{ name: IMPORT_KEY_FIELD.COMMON_DIVISION, key: 'groupe' },
],
additionalInformations: {
groupe: 'CP',
dateofbirth: '2020-02-01',
},
{ name: IMPORT_KEY_FIELD.COMMON_DIVISION, key: 'groupe' },
],
additionalInformations: {
groupe: 'CP',
dateofbirth: '2020-02-01',
},
});
expect(learner.division).to.equal('CP');
expect(learner.birthdate).to.deep.equal('2020-02-01');
});
expect(learner.division).to.equal('CP');
expect(learner.birthdate).to.deep.equal('2020-02-01');
});

it('should throw an ObjectValidationError when id is not valid', function () {
Expand Down

0 comments on commit e7761ff

Please sign in to comment.