diff --git a/api/db/seeds/data/team-prescription/build-organization-learner-import-formats.js b/api/db/seeds/data/team-prescription/build-organization-learner-import-formats.js index e71ad9d0d86..dc2af5368af 100644 --- a/api/db/seeds/data/team-prescription/build-organization-learner-import-formats.js +++ b/api/db/seeds/data/team-prescription/build-organization-learner-import-formats.js @@ -7,23 +7,25 @@ export async function buildOrganizationLearnerImportFormat(databaseBuilder) { name: 'ONDE', fileType: 'csv', config: { - acceptedEncoding: [], - unicityColumns: ['identifiant'], + acceptedEncoding: ['utf8'], + unicityColumns: ['INE'], validationRules: { formats: [ - { name: 'nom', type: 'string' }, - { name: 'prénom', type: 'string' }, - { name: 'identifiant', type: 'string' }, - { name: 'classe', type: 'string' }, - { name: 'date de naissance', type: 'date', format: 'DD/MM/YYYY' }, + { name: 'Nom élève', type: 'string', required: true }, + { name: 'Prénom élève', type: 'string', required: true }, + { name: 'INE', type: 'string', required: true }, + { name: 'Niveau', type: 'string', required: true }, + { name: 'Libellé classe', type: 'string', required: true }, + { name: 'Date de naissance', type: 'date', format: 'DD/MM/YYYY', required: true }, ], }, headers: [ - { name: 'nom', property: 'lastName', required: true }, - { name: 'prénom', property: 'firstName', required: true }, - { name: 'identifiant', required: true }, - { name: 'classe', required: true }, - { name: 'date de naissance', required: true }, + { name: 'Nom élève', property: 'lastName', required: true }, + { name: 'Prénom élève', property: 'firstName', required: true }, + { name: 'INE', required: true }, + { name: 'Niveau', required: true }, + { name: 'Libellé classe', required: true }, + { name: 'Date de naissance', required: true }, ], }, createdAt: new Date('2024-01-01'), diff --git a/api/src/prescription/learner-management/application/organization-learners-controller.js b/api/src/prescription/learner-management/application/organization-learners-controller.js index 1bb2f064030..57f6a749684 100644 --- a/api/src/prescription/learner-management/application/organization-learners-controller.js +++ b/api/src/prescription/learner-management/application/organization-learners-controller.js @@ -17,12 +17,16 @@ const deleteOrganizationLearners = async function (request, h) { }; const importOrganizationLearnerFromFeature = async function (request, h) { - await ApplicationTransaction.execute(async () => { - const organizationId = request.params.organizationId; - const userId = request.auth.credentials.userId; + const organizationId = request.params.organizationId; + const userId = request.auth.credentials.userId; + await ApplicationTransaction.execute(async () => { await usecases.sendOrganizationLearnersFile({ payload: request.payload, organizationId, userId }); + }); + await ApplicationTransaction.execute(async () => { await usecases.validateOrganizationLearnersFile({ organizationId }); + }); + await ApplicationTransaction.execute(async () => { await usecases.saveOrganizationLearnersFile({ organizationId }); }); diff --git a/api/src/prescription/learner-management/infrastructure/repositories/organization-learner-import-format-repository.js b/api/src/prescription/learner-management/infrastructure/repositories/organization-learner-import-format-repository.js index 97b445868b9..7cc64ac3f26 100644 --- a/api/src/prescription/learner-management/infrastructure/repositories/organization-learner-import-format-repository.js +++ b/api/src/prescription/learner-management/infrastructure/repositories/organization-learner-import-format-repository.js @@ -23,7 +23,7 @@ const get = async function (organizationId) { if (!configResult) return null; const result = await knex('organization-learner-import-formats') - .where('id', configResult.params.organizationLearnerImportId) + .where('id', configResult.params.organizationLearnerImportFormatId) .first(); if (!result) return null; diff --git a/api/src/prescription/learner-management/infrastructure/serializers/csv/common-csv-learner-parser.js b/api/src/prescription/learner-management/infrastructure/serializers/csv/common-csv-learner-parser.js index 1e079658f10..73dfa2198c8 100644 --- a/api/src/prescription/learner-management/infrastructure/serializers/csv/common-csv-learner-parser.js +++ b/api/src/prescription/learner-management/infrastructure/serializers/csv/common-csv-learner-parser.js @@ -102,7 +102,7 @@ class CommonCsvLearnerParser { #checkColumns(parsedColumns) { // Required columns - const mandatoryColumn = this.#columns.filter((c) => c.isRequired); + const mandatoryColumn = this.#columns.filter((c) => c.required); mandatoryColumn.forEach((colum) => { if (!parsedColumns.includes(colum.name)) { diff --git a/api/src/prescription/organization-learner/application/api/models/OrganizationLearner.js b/api/src/prescription/organization-learner/application/api/models/OrganizationLearner.js index 916936fd185..86d4232f731 100644 --- a/api/src/prescription/organization-learner/application/api/models/OrganizationLearner.js +++ b/api/src/prescription/organization-learner/application/api/models/OrganizationLearner.js @@ -1,9 +1,9 @@ export class OrganizationLearner { - constructor({ id, firstName, lastName, classe, organizationId }) { + constructor({ id, firstName, lastName, organizationId, ...attributes }) { this.id = id; this.firstName = firstName; this.lastName = lastName; - this.division = classe; + this.division = attributes['Libellé classe']; this.organizationId = organizationId; } } diff --git a/api/src/school/scripts/create-school-learners.js b/api/src/school/scripts/create-school-learners.js index 391228d3046..c6d8aa97ed1 100644 --- a/api/src/school/scripts/create-school-learners.js +++ b/api/src/school/scripts/create-school-learners.js @@ -80,7 +80,7 @@ async function buildLearners({ organizationId, quantity = STUDENT_NAMES.length } organizationId, firstName: studentName.firstName, lastName: studentName.lastName, - division: 'CM2', + attributes: { 'Libellé classe': 'CM2' }, }); }); logger.info(`${quantity} learners created.`); diff --git a/api/tests/prescription/learner-management/acceptance/application/organization-learners-route_test.js b/api/tests/prescription/learner-management/acceptance/application/organization-learners-route_test.js index fac9eaee9e5..606ddc6d0ac 100644 --- a/api/tests/prescription/learner-management/acceptance/application/organization-learners-route_test.js +++ b/api/tests/prescription/learner-management/acceptance/application/organization-learners-route_test.js @@ -28,7 +28,7 @@ describe('Acceptance | Application | organization-learners', function () { const buffer = `column_firstname;column_lastname;hobby\n` + 'sasha;du bourg palette;pokemon hunter\n'; const organizationId = databaseBuilder.factory.buildOrganization().id; const featureId = databaseBuilder.factory.buildFeature({ key: ORGANIZATION_FEATURE.LEARNER_IMPORT.key }).id; - const organizationLearnerImportFormatsId = databaseBuilder.factory.buildOrganizationLearnerImportFormat({ + const organizationLearnerImportFormatId = databaseBuilder.factory.buildOrganizationLearnerImportFormat({ name: 'ONDE', fileType: 'csv', config: { @@ -46,7 +46,7 @@ describe('Acceptance | Application | organization-learners', function () { databaseBuilder.factory.buildOrganizationFeature({ organizationId, featureId, - params: { organizationLearnerImportId: organizationLearnerImportFormatsId }, + params: { organizationLearnerImportFormatId }, }); databaseBuilder.factory.buildMembership({ diff --git a/api/tests/prescription/learner-management/integration/infrastructure/repositories/organization-learner-import-format-repository_test.js b/api/tests/prescription/learner-management/integration/infrastructure/repositories/organization-learner-import-format-repository_test.js index 690c9334698..cf7bf4ea440 100644 --- a/api/tests/prescription/learner-management/integration/infrastructure/repositories/organization-learner-import-format-repository_test.js +++ b/api/tests/prescription/learner-management/integration/infrastructure/repositories/organization-learner-import-format-repository_test.js @@ -32,12 +32,13 @@ describe('Integration | Repository | Organization Learner Management | Organizat key: ORGANIZATION_FEATURE.LEARNER_IMPORT.key, }).id; - const organizationLearnerImportId = databaseBuilder.factory.buildOrganizationLearnerImportFormat(importConfig).id; + const organizationLearnerImportFormatId = + databaseBuilder.factory.buildOrganizationLearnerImportFormat(importConfig).id; databaseBuilder.factory.buildOrganizationFeature({ organizationId, featureId, - params: { organizationLearnerImportId }, + params: { organizationLearnerImportFormatId }, }); await databaseBuilder.commit(); diff --git a/api/tests/prescription/learner-management/unit/application/organization-learner-controller_test.js b/api/tests/prescription/learner-management/unit/application/organization-learners-controller_test.js similarity index 88% rename from api/tests/prescription/learner-management/unit/application/organization-learner-controller_test.js rename to api/tests/prescription/learner-management/unit/application/organization-learners-controller_test.js index 9c6c66af1de..0dfc754ad5f 100644 --- a/api/tests/prescription/learner-management/unit/application/organization-learner-controller_test.js +++ b/api/tests/prescription/learner-management/unit/application/organization-learners-controller_test.js @@ -7,10 +7,8 @@ describe('Unit | Application | Learner Management | organization-learner-control let saveOrganizationLearnersFileStub, sendOrganizationLearnersFileStub, validateOrganizationLearnersFileStub; beforeEach(function () { - sinon.stub(ApplicationTransaction, 'execute').callsFake((lambda) => { - return lambda(); - }); - + sinon.stub(ApplicationTransaction, 'execute'); + ApplicationTransaction.execute.callsFake((callback) => callback()); saveOrganizationLearnersFileStub = sinon.stub(usecases, 'saveOrganizationLearnersFile'); sendOrganizationLearnersFileStub = sinon.stub(usecases, 'sendOrganizationLearnersFile'); validateOrganizationLearnersFileStub = sinon.stub(usecases, 'validateOrganizationLearnersFile'); @@ -18,7 +16,7 @@ describe('Unit | Application | Learner Management | organization-learner-control it('should call usecases in correct order', async function () { const userId = Symbol('userId'); - const organizationId = Symbol('orgnaizationId'); + const organizationId = Symbol('organizationId'); const payload = Symbol('payload'); const request = { auth: { credentials: { userId } }, @@ -28,7 +26,7 @@ describe('Unit | Application | Learner Management | organization-learner-control const response = await organizationLearnersController.importOrganizationLearnerFromFeature(request, hFake); - expect(ApplicationTransaction.execute.called, 'ApplicationTransaction.execute').to.be.true; + expect(ApplicationTransaction.execute.calledThrice, 'ApplicationTransaction.execute').to.be.true; expect( sinon.assert.callOrder( sendOrganizationLearnersFileStub, diff --git a/api/tests/prescription/learner-management/unit/infrastructure/serializers/csv/common-csv-learner-parser_test.js b/api/tests/prescription/learner-management/unit/infrastructure/serializers/csv/common-csv-learner-parser_test.js index e5fca85f18a..208c88b2afa 100644 --- a/api/tests/prescription/learner-management/unit/infrastructure/serializers/csv/common-csv-learner-parser_test.js +++ b/api/tests/prescription/learner-management/unit/infrastructure/serializers/csv/common-csv-learner-parser_test.js @@ -15,17 +15,17 @@ describe('Unit | Infrastructure | CommonCsvLearnerParser', function () { { name: 'nom', property: 'lastName', - isRequired: true, + required: true, }, { name: 'prénom', property: 'firstName', - isRequired: false, + required: false, }, { name: 'GodZilla', property: 'kaiju', - isRequired: true, + required: true, }, ], acceptedEncoding: ['utf8'], @@ -44,7 +44,7 @@ describe('Unit | Infrastructure | CommonCsvLearnerParser', function () { { name: 'prénom', property: 'firstName', - isRequired: false, + required: false, checkEncoding: true, }, ], @@ -86,17 +86,17 @@ describe('Unit | Infrastructure | CommonCsvLearnerParser', function () { { name: 'nom', property: 'lastName', - isRequired: true, + required: true, }, { name: 'prénom', property: 'firstName', - isRequired: false, + required: false, }, { name: 'GodZilla', property: 'kaiju', - isRequired: true, + required: true, }, ], acceptedEncoding: ['utf8'], @@ -193,12 +193,12 @@ describe('Unit | Infrastructure | CommonCsvLearnerParser', function () { { name: 'nom', property: 'lastName', - isRequired: true, + required: true, }, { name: 'prénom', property: 'firstName', - isRequired: false, + required: false, }, ], acceptedEncoding: ['utf8'], diff --git a/api/tests/prescription/organization-learner/unit/application/api/models/OrganizationLearner_test.js b/api/tests/prescription/organization-learner/unit/application/api/models/OrganizationLearner_test.js index b7772acb89b..7210216b2d3 100644 --- a/api/tests/prescription/organization-learner/unit/application/api/models/OrganizationLearner_test.js +++ b/api/tests/prescription/organization-learner/unit/application/api/models/OrganizationLearner_test.js @@ -7,7 +7,7 @@ describe('Unit | Application| API | Models | OrganizationLearner', function () { const organizationLearner = new OrganizationLearner({ firstName: 'Jean-Hugues', lastName: 'Delaforêt', - classe: '4ème', + 'Libellé classe': '4ème', organizationId: 358, }); diff --git a/api/tests/prescription/organization-learner/unit/application/api/organization-learners-api_test.js b/api/tests/prescription/organization-learner/unit/application/api/organization-learners-api_test.js index 0d97ba24482..d3fb5ea0c35 100644 --- a/api/tests/prescription/organization-learner/unit/application/api/organization-learners-api_test.js +++ b/api/tests/prescription/organization-learner/unit/application/api/organization-learners-api_test.js @@ -12,7 +12,7 @@ describe('Unit | API | Organization Learner', function () { id: 1242, firstName: 'Paul', lastName: 'Henri', - classe: '3ème', + 'Libellé classe': '3ème', organizationId, }; const expectedOrganizationLearner1 = new OrganizationLearner(organizationLearner1); @@ -20,7 +20,7 @@ describe('Unit | API | Organization Learner', function () { id: 1243, firstName: 'Pierre', lastName: 'Jacques', - classe: '3ème', + 'Libellé classe': '3ème', organizationId, }; const expectedOrganizationLearner2 = new OrganizationLearner(organizationLearner2); @@ -65,7 +65,7 @@ describe('Unit | API | Organization Learner', function () { id: 1242, firstName: 'Paul', lastName: 'Henri', - classe: '3ème', + 'Libellé classe': '3ème', organizationId, }; const expectedOrganizationLearner1 = new OrganizationLearner(organizationLearner1); @@ -100,7 +100,7 @@ describe('Unit | API | Organization Learner', function () { id: 1242, firstName: 'Paul', lastName: 'Henri', - classe: '3ème', + 'Libellé classe': '3ème', organizationId: 356, }; @@ -114,7 +114,7 @@ describe('Unit | API | Organization Learner', function () { // then expect(learner).to.be.instanceOf(OrganizationLearner); - expect(learner.division).to.equal(organizationLearner.classe); + expect(learner.division).to.equal(organizationLearner['Libellé classe']); }); }); });