Skip to content

Commit

Permalink
[BUGFIX] Petites corrections pour faire fonctionner l'import ONDE (Pi…
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Apr 24, 2024
2 parents 0e53a32 + 6160a4d commit d3b5d48
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion api/src/school/scripts/create-school-learners.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -46,7 +46,7 @@ describe('Acceptance | Application | organization-learners', function () {
databaseBuilder.factory.buildOrganizationFeature({
organizationId,
featureId,
params: { organizationLearnerImportId: organizationLearnerImportFormatsId },
params: { organizationLearnerImportFormatId },
});

databaseBuilder.factory.buildMembership({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ 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');
});

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 } },
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -44,7 +44,7 @@ describe('Unit | Infrastructure | CommonCsvLearnerParser', function () {
{
name: 'prénom',
property: 'firstName',
isRequired: false,
required: false,
checkEncoding: true,
},
],
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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);
const organizationLearner2 = {
id: 1243,
firstName: 'Pierre',
lastName: 'Jacques',
classe: '3ème',
'Libellé classe': '3ème',
organizationId,
};
const expectedOrganizationLearner2 = new OrganizationLearner(organizationLearner2);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
};

Expand All @@ -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']);
});
});
});

0 comments on commit d3b5d48

Please sign in to comment.