Skip to content

Commit

Permalink
feat(api): add exportableColumns getter on OrganizationImportFormat m…
Browse files Browse the repository at this point in the history
…odel
  • Loading branch information
lionelB committed Sep 19, 2024
1 parent e314c3c commit 32c8ab7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class OrganizationLearnerImportFormat {
};
});
}
get exportableColumns() {
return this.config.headers.flatMap(({ name, config }) => (config?.exportable ? { columnName: name } : []));
}

/**
* @function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -256,8 +256,8 @@ describe('Unit | Models | OrganizationLearnerImportFormat', function () {
expect(organizationLearnerImportFormat.headersFields).to.deep.equal([
{ 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 },
]);
});
Expand All @@ -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);
});
});
});

0 comments on commit 32c8ab7

Please sign in to comment.