Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Ordonner les skillName afin de garantir l'ordre des colonnes lors de l'export de résultat (Pix-16196) #11220

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/src/shared/domain/models/CampaignLearningContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class CampaignLearningContent extends LearningContent {
get competences() {
return super.competences.sort((a, b) => a.index.localeCompare(b.index));
}

get skills() {
return this.competences.flatMap((competence) => competence.skills.sort((a, b) => a.name.localeCompare(b.name)));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: pourquoi ne pas faire un super.skills ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour avoir les skills trié par compétence. le super.skills ne se base pas sur les compétence pour le trier. Du coup on aurait potentiellement des skills de la competence 4 avant la compétence 1 etc....

}

export { CampaignLearningContent };
49 changes: 33 additions & 16 deletions api/tests/shared/unit/domain/models/CampaignLearningContent_test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { expect } from 'chai';

import { buildArea } from '../../../../../db/database-builder/factory/learning-content/build-area.js';
import { buildCompetence } from '../../../../../db/database-builder/factory/learning-content/build-competence.js';
import { buildFramework } from '../../../../../db/database-builder/factory/learning-content/build-framework.js';
import { buildSkill } from '../../../../../db/database-builder/factory/learning-content/build-skill.js';
import { buildTube } from '../../../../../db/database-builder/factory/learning-content/build-tube.js';
import { CampaignLearningContent } from '../../../../../src/shared/domain/models/CampaignLearningContent.js';
import { domainBuilder } from '../../../../test-helper.js';

Expand All @@ -13,12 +9,26 @@ describe('Unit | Domain | Models | CampaignLearningContent', function () {

beforeEach(function () {
framework = buildFramework({ id: 'frameworkId', name: 'someFramework' });
const skill = buildSkill({ id: 'skillId', tubeId: 'tubeId' });
const tube = buildTube({ id: 'tubeId', competenceId: 'competenceId', skills: [skill] });
const area1 = buildArea({ id: 'areaId', code: '5', frameworkId: framework.id });
const area2 = buildArea({ id: 'areaId', code: '2', frameworkId: framework.id });
const competence1 = buildCompetence({ id: 'competenceId', index: '5.1', tubes: [tube] });
const competence2 = buildCompetence({ id: 'competenceId', index: '2.4', tubes: [tube] });
const tube1 = domainBuilder.buildTube({
id: 'tubeId',
competenceId: 'competenceId1',
skills: [
domainBuilder.buildSkill({ id: 'skillId1', tubeId: 'tubeId1', name: '@skill2' }),
domainBuilder.buildSkill({ id: 'skillId3', tubeId: 'tubeId1', name: '@skill1' }),
],
});
const tube2 = domainBuilder.buildTube({
id: 'tubeId2',
competenceId: 'competenceId2',
skills: [
domainBuilder.buildSkill({ id: 'idSkill2', tubeId: 'tubeId2', name: '@yep1' }),
domainBuilder.buildSkill({ id: 'skillId4', tubeId: 'tubeId2', name: '@bouh1' }),
],
});
const area1 = domainBuilder.buildArea({ id: 'areaId', code: '5', frameworkId: framework.id });
const area2 = domainBuilder.buildArea({ id: 'areaId', code: '2', frameworkId: framework.id });
const competence1 = domainBuilder.buildCompetence({ id: 'competenceId1', index: '5.1', tubes: [tube1] });
const competence2 = domainBuilder.buildCompetence({ id: 'competenceId2', index: '2.4', tubes: [tube2] });
area1.competences = [competence1];
area2.competences = [competence2];
framework.areas = [area2, area1];
Expand All @@ -28,17 +38,24 @@ describe('Unit | Domain | Models | CampaignLearningContent', function () {
it('should return competences sorted by index', function () {
const learningContent = domainBuilder.buildLearningContent([framework]);
const campaignLearningContent = new CampaignLearningContent(learningContent.frameworks);
expect(campaignLearningContent.competences).to.deep.equal(
learningContent.competences.sort((a, b) => a.index.localeCompare(b.index)),
);
expect(campaignLearningContent.competences.map((competence) => competence.index)).to.deep.equal(['2.4', '5.1']);
});

it('should return areas sorted by code', function () {
const learningContent = domainBuilder.buildLearningContent([framework]);
const campaignLearningContent = new CampaignLearningContent(learningContent.frameworks);
expect(campaignLearningContent.areas).to.deep.equal(
learningContent.areas.sort((a, b) => a.code.localeCompare(b.code)),
);
expect(campaignLearningContent.areas.map((area) => area.code)).to.deep.equal(['2', '5']);
});

it('should return skills sorted by competence then by skill name', function () {
const learningContent = domainBuilder.buildLearningContent([framework]);
const campaignLearningContent = new CampaignLearningContent(learningContent.frameworks);
expect(campaignLearningContent.skills.map((skill) => skill.name)).to.deep.equal([
'@bouh1',
'@yep1',
'@skill1',
'@skill2',
]);
});
});
});