Skip to content

Commit

Permalink
bugfix(orga): added sorting of competences and areas into CampaignLea…
Browse files Browse the repository at this point in the history
…rning model
  • Loading branch information
alicegoarnisson authored Jan 17, 2025
1 parent d6a2c7a commit bed45a0
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 45 deletions.
4 changes: 2 additions & 2 deletions api/src/shared/domain/models/CampaignLearningContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class CampaignLearningContent {
}

get competences() {
return this._learningContent.competences;
return this._learningContent.competences.sort((a, b) => a.index.localeCompare(b.index));
}

get areas() {
return this._learningContent.areas;
return this._learningContent.areas.sort((a, b) => a.code.localeCompare(b.code));
}

findSkill(skillId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('Unit | DevComp | Infrastructure | Serializers | Jsonapi | training-ser
{
attributes: {
id: `recArea1_${trainingTriggerId}`,
code: 5,
code: '5',
color: 'red',
title: 'Super domaine',
},
Expand Down Expand Up @@ -273,7 +273,7 @@ describe('Unit | DevComp | Infrastructure | Serializers | Jsonapi | training-ser
},
{
attributes: {
code: 5,
code: '5',
color: 'red',
id: 'recArea1_789',
title: 'Super domaine',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('Unit | DevComp | Infrastructure | Serializers | Jsonapi | training-tri
},
{
attributes: {
code: 5,
code: '5',
color: 'red',
title: 'Super domaine',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
});

describe('#toCsvLine', function () {
let organization, campaign, targetProfile, learningContent, stageCollection;
let organization, campaign, targetProfile, learningContent, stageCollection, areas, competences;
const createdAt = new Date('2020-03-01T10:00:00Z');
const createdAtFormated = '01/03/2020 11:00';
const sharedAt = new Date('2020-04-01T10:00:00Z');
Expand All @@ -22,6 +22,8 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaign = domainBuilder.buildCampaign({ idPixLabel: null });
targetProfile = domainBuilder.buildTargetProfile();
learningContent = domainBuilder.buildLearningContent.withSimpleContent();
areas = learningContent.areas;
competences = learningContent.competences;
stageCollection = domainBuilder.buildStageCollectionForUserCampaignResults({
campaignId: campaign.id,
stages: [],
Expand All @@ -42,9 +44,11 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaignParticipationInfo,
targetProfile,
learningContent,
competences,
areas,
stageCollection,
participantKnowledgeElementsByCompetenceId: {
[learningContent.competences[0].id]: [],
[competences[0].id]: [],
},
translate,
});
Expand Down Expand Up @@ -91,9 +95,11 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaignParticipationInfo,
targetProfile,
learningContent,
competences,
areas,
stageCollection,
participantKnowledgeElementsByCompetenceId: {
[learningContent.competences[0].id]: [],
[competences[0].id]: [],
},
translate,
});
Expand Down Expand Up @@ -143,9 +149,11 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
additionalHeaders,
targetProfile,
learningContent,
competences,
areas,
stageCollection,
participantKnowledgeElementsByCompetenceId: {
[learningContent.competences[0].id]: [],
[competences[0].id]: [],
},
translate,
});
Expand Down Expand Up @@ -195,9 +203,11 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
additionalHeaders: [],
targetProfile,
learningContent,
competences,
areas,
stageCollection,
participantKnowledgeElementsByCompetenceId: {
[learningContent.competences[0].id]: [],
[competences[0].id]: [],
},
translate,
});
Expand Down Expand Up @@ -248,9 +258,11 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaignParticipationInfo,
targetProfile,
learningContent,
competences,
areas,
stageCollection,
participantKnowledgeElementsByCompetenceId: {
[learningContent.competences[0].id]: [],
[competences[0].id]: [],
},
translate,
});
Expand Down Expand Up @@ -308,7 +320,7 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
learningContent,
stageCollection,
participantKnowledgeElementsByCompetenceId: {
[learningContent.competences[0].id]: [],
[competences[0].id]: [],
},
translate,
});
Expand All @@ -317,7 +329,7 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
const csvLine = campaignAssessmentCsvLine.toCsvLine();

// then
const csvExcpectedLine =
const csvExpectedLine =
`"${organization.name}";` +
`${campaign.id};` +
`"${campaign.code}";` +
Expand All @@ -332,17 +344,11 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
`"${createdAtFormated}";` +
'"Non";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA"' +
'\n';

// then
expect(csvLine).to.equal(csvExcpectedLine);
expect(csvLine).to.equal(csvExpectedLine);
});
});

Expand All @@ -369,7 +375,7 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
learningContent,
stageCollection,
participantKnowledgeElementsByCompetenceId: {
[learningContent.competences[0].id]: [],
[competences[0].id]: [],
},
translate,
});
Expand All @@ -392,12 +398,6 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
`"${createdAtFormated}";` +
'"Non";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA"' +
'\n';

Expand Down Expand Up @@ -500,6 +500,8 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaignParticipationInfo,
targetProfile,
learningContent,
competences: learningContent.competences,
areas: learningContent.areas,
stageCollection,
participantKnowledgeElementsByCompetenceId,
translate,
Expand Down Expand Up @@ -562,6 +564,8 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaignParticipationInfo,
targetProfile,
learningContent,
competences,
areas,
stageCollection,
participantKnowledgeElementsByCompetenceId,
translate,
Expand Down Expand Up @@ -593,15 +597,6 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA";' +
'"NA"' +
'\n';

Expand All @@ -625,9 +620,11 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaignParticipationInfo,
targetProfile,
learningContent,
competences,
areas,
stageCollection,
participantKnowledgeElementsByCompetenceId: {
[learningContent.competences[0].id]: [],
[competences[0].id]: [],
},
acquiredBadges: [badge],
translate,
Expand Down Expand Up @@ -689,9 +686,11 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaignParticipationInfo,
targetProfile,
learningContent,
competences,
areas,
stageCollection,
participantKnowledgeElementsByCompetenceId: {
[learningContent.competences[0].id]: [knowledgeElement],
[competences[0].id]: [knowledgeElement],
},
acquiredBadges: { [campaignParticipationInfo.campaignParticipationId]: [{ title: badge.title }] },
translate,
Expand Down Expand Up @@ -746,9 +745,11 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaignParticipationInfo,
targetProfile,
learningContent,
competences,
areas,
stageCollection,
participantKnowledgeElementsByCompetenceId: {
[learningContent.competences[0].id]: [knowledgeElement],
[competences[0].id]: [knowledgeElement],
},
translate,
});
Expand Down Expand Up @@ -849,6 +850,8 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaignParticipationInfo,
targetProfile,
learningContent,
areas: learningContent.areas,
competences: learningContent.competences,
stageCollection,
participantKnowledgeElementsByCompetenceId,
translate,
Expand Down Expand Up @@ -900,6 +903,8 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaignParticipationInfo,
targetProfile,
learningContent,
competences: learningContent.competences,
areas: learningContent.areas,
stageCollection,
participantKnowledgeElementsByCompetenceId,
translate,
Expand Down Expand Up @@ -950,6 +955,8 @@ describe('Unit | Infrastructure | Utils | CampaignAssessmentResultLine', functio
campaignParticipationInfo,
targetProfile,
learningContent,
competences,
areas,
stageCollection,
participantKnowledgeElementsByCompetenceId,
translate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Unit | Serializer | CSV | campaign-assessment-export', function () {
badges: [],
};
stageCollection = {};
learningContent = { skillNames: [], competence: [], areas: [] };
learningContent = { skillNames: [], competences: [], areas: [] };
campaign = {};

const listSkills1 = domainBuilder.buildSkillCollection({ name: '@web', minLevel: 1, maxLevel: 5 });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { expect } from 'chai';

import { Area } from '../../../../../src/shared/domain/models/Area.js';
import { CampaignLearningContent } from '../../../../../src/shared/domain/models/CampaignLearningContent.js';
import { Skill } from '../../../../../src/shared/domain/models/Skill.js';
import { Tube } from '../../../../../src/shared/domain/models/Tube.js';

describe('Unit | Domain | Models | CampaignLearningContent', function () {
let skills, areasSorted, tubesSorted, competencesSorted, areas, competences, jaffaArea, wildStrawberryArea;

beforeEach(function () {
jaffaArea = new Area({ id: 'jaffaArea', code: '1', name: 'area 1', color: 'jaffa' });
wildStrawberryArea = new Area({
id: 'wildStrawberryArea',
code: '2',
name: 'area 2',
color: 'wild-strawberry',
});
areas = [wildStrawberryArea, jaffaArea];
areasSorted = [jaffaArea, wildStrawberryArea];

skills = [new Skill({ name: '@web3' }), new Skill({ name: '@web2' })];

tubesSorted = [new Tube({ skills })];

(competences = [
{ id: 2, name: 'Désobéissance civile', index: '6.9', skillIds: [2, 3, 4], areaId: 'wildStrawberryArea' },
{ id: 1, name: 'Economie symbiotique', index: '5.1', skillIds: [1], areaId: 'jaffaArea' },
{ id: 3, name: 'Démocratie liquide', index: '8.6', skillIds: [5, 6], areaId: 'wildStrawberryArea' },
]),
(competencesSorted = [
{ id: 1, name: 'Economie symbiotique', index: '5.1', skillIds: [1], areaId: 'jaffaArea' },
{ id: 2, name: 'Désobéissance civile', index: '6.9', skillIds: [2, 3, 4], areaId: 'wildStrawberryArea' },
{ id: 3, name: 'Démocratie liquide', index: '8.6', skillIds: [5, 6], areaId: 'wildStrawberryArea' },
]);
});

describe('building model', function () {
it('should return competences sorted by index', function () {
const learningContent = {
competences,
areas: [wildStrawberryArea, jaffaArea],
};
const campaignLearningContent = new CampaignLearningContent({
skills,
tubesSorted,
competences: learningContent.competences,
areas: [wildStrawberryArea, jaffaArea],
});
expect(campaignLearningContent.competences).to.deep.equal(competencesSorted);
});

it('should return areas sorted by code', function () {
const learningContent = new CampaignLearningContent({
skills,
tubesSorted,
competences: competencesSorted,
areas,
});
const campaignLearningContent = new CampaignLearningContent({
skills,
tubesSorted,
competencesSorted,
areas: learningContent.areas,
});
expect(campaignLearningContent.areas).to.deep.equal(areasSorted);
});
});
});
6 changes: 1 addition & 5 deletions api/tests/tooling/domain-builder/factory/build-area.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Area } from '../../../../src/shared/domain/models/Area.js';

const buildArea = function ({
id = 'recArea123',
code = 5,
code = '5',
title = 'Super domaine',
competences = [],
color = 'red',
Expand All @@ -20,10 +20,6 @@ const buildArea = function ({
frameworkId,
});

// c koi ce truc
//competences.forEach((competence) => {
// competence.area = area;
//});
return area;
};

Expand Down

0 comments on commit bed45a0

Please sign in to comment.