diff --git a/api/db/seeds/data/common/organization-learner-import-formats.js b/api/db/seeds/data/common/organization-learner-import-formats.js index 8d73175a10f..b4d46721d46 100644 --- a/api/db/seeds/data/common/organization-learner-import-formats.js +++ b/api/db/seeds/data/common/organization-learner-import-formats.js @@ -77,7 +77,7 @@ export const organizationLearnerImportFormat = async function ({ databaseBuilder headers: [ { key: 1, name: 'Nom apprenant', property: 'lastName', required: true }, { key: 2, name: 'Prénom apprenant', property: 'firstName', required: true }, - { key: 3, name: 'Classe', required: true }, + { key: 3, name: 'Classe', required: true, config: { exportable: true } }, { key: 4, name: 'Date de naissance', required: true }, ], }, diff --git a/api/src/prescription/learner-management/domain/models/OrganizationLearnerImportFormat.js b/api/src/prescription/learner-management/domain/models/OrganizationLearnerImportFormat.js index 56d709d4412..7a372866620 100644 --- a/api/src/prescription/learner-management/domain/models/OrganizationLearnerImportFormat.js +++ b/api/src/prescription/learner-management/domain/models/OrganizationLearnerImportFormat.js @@ -75,6 +75,9 @@ class OrganizationLearnerImportFormat { }; }); } + get exportableColumns() { + return this.config.headers.flatMap(({ name, config }) => (config?.exportable ? { columnName: name } : [])); + } /** * @function diff --git a/api/tests/prescription/learner-management/unit/domain/models/OrganizationLearnerImportFormat_test.js b/api/tests/prescription/learner-management/unit/domain/models/OrganizationLearnerImportFormat_test.js index c3b099137d2..4822404e156 100644 --- a/api/tests/prescription/learner-management/unit/domain/models/OrganizationLearnerImportFormat_test.js +++ b/api/tests/prescription/learner-management/unit/domain/models/OrganizationLearnerImportFormat_test.js @@ -31,8 +31,8 @@ describe('Unit | Models | OrganizationLearnerImportFormat', function () { headers: [ { key: 1, name: 'Nom apprenant', property: 'lastName', required: true }, { key: 2, name: 'Prénom apprenant', property: 'firstName', required: true }, - { key: 3, name: 'catégorie', required: true }, - { key: 4, name: 'Date de naissance', required: true }, + { key: 3, name: 'catégorie', required: true, config: { exportable: true } }, + { key: 4, name: 'Date de naissance', required: true, config: { exportable: true } }, { key: 5, name: 'unicity key', required: true }, ], filterableColumns: [ @@ -283,4 +283,27 @@ describe('Unit | Models | OrganizationLearnerImportFormat', function () { }); }); }); + + describe('#exportableColumns', function () { + it('should return exportable columns', function () { + const organizationLearnerImportFormat = new OrganizationLearnerImportFormat( + organizationLearnerImportFormatPayload, + ); + expect(organizationLearnerImportFormat.exportableColumns).to.deep.equals([ + { columnName: 'catégorie' }, + { columnName: 'Date de naissance' }, + ]); + }); + + it('should return empty when there is no exportable columns', function () { + organizationLearnerImportFormatPayload.config.headers = [ + { key: 1, name: 'Nom apprenant', property: 'lastName', required: true }, + ]; + + const organizationLearnerImportFormat = new OrganizationLearnerImportFormat( + organizationLearnerImportFormatPayload, + ); + expect(organizationLearnerImportFormat.exportableColumns).lengthOf(0); + }); + }); });