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] Garder toujours le même ordre de colonnes dans le fichier d'export des résultats (PIX-16099) #11138

Merged
merged 2 commits into from
Jan 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class CampaignAssessmentResultLine {
targetProfile,
additionalHeaders,
learningContent,
areas,
competences,
stageCollection,
participantKnowledgeElementsByCompetenceId,
acquiredBadges,
Expand All @@ -30,6 +32,8 @@ class CampaignAssessmentResultLine {
this.campaignParticipationInfo = campaignParticipationInfo;
this.targetProfile = targetProfile;
this.learningContent = learningContent;
this.areas = areas;
this.competences = competences;
this.stageCollection = stageCollection;
this.targetedKnowledgeElementsCount = _.sum(
_.map(participantKnowledgeElementsByCompetenceId, (knowledgeElements) => knowledgeElements.length),
Expand Down Expand Up @@ -73,7 +77,7 @@ class CampaignAssessmentResultLine {
}

_makeCompetenceColumns() {
return _.flatMap(this.learningContent.competences, (competence) =>
return _.flatMap(this.competences, (competence) =>
this._makeSharedStatsColumns({
id: competence.id,
...this._getStatsForCompetence(competence),
Expand All @@ -82,7 +86,7 @@ class CampaignAssessmentResultLine {
}

_makeAreaColumns() {
return _.flatMap(this.learningContent.areas, ({ id, competences }) => {
return _.flatMap(this.areas, ({ id, competences }) => {
const areaCompetenceStats = competences.map(this._getStatsForCompetence);

const targetedSkillCount = _.sumBy(areaCompetenceStats, 'targetedSkillCount');
Expand Down Expand Up @@ -156,8 +160,8 @@ class CampaignAssessmentResultLine {

_makeNotSharedColumns() {
return [
...this._makeEmptyColumns(this.learningContent.competences.length * STATS_COLUMNS_COUNT),
...this._makeEmptyColumns(this.learningContent.areas.length * STATS_COLUMNS_COUNT),
...this._makeEmptyColumns(this.competences.length * STATS_COLUMNS_COUNT),
...this._makeEmptyColumns(this.areas.length * STATS_COLUMNS_COUNT),
...(this.organization.showSkills ? this._makeEmptyColumns(this.learningContent.skills.length) : []),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CampaignAssessmentExport {
this.stageCollection = stageCollection;
this.idPixLabel = campaign.idPixLabel;
this.competences = learningContent.competences;
this.areas = learningContent.areas;
this.translate = translate;
this.additionalHeaders = additionalHeaders;
}
Expand Down Expand Up @@ -117,15 +118,15 @@ class CampaignAssessmentExport {
}

#competenceColumnHeaders() {
return _.flatMap(this.learningContent.competences, (competence) => [
return _.flatMap(this.competences, (competence) => [
this.translate('campaign-export.assessment.skill.mastery-percentage', { name: competence.name }),
this.translate('campaign-export.assessment.skill.total-items', { name: competence.name }),
this.translate('campaign-export.assessment.skill.items-successfully-completed', { name: competence.name }),
]);
}

#areaColumnHeaders() {
return _.flatMap(this.learningContent.areas, (area) => [
return _.flatMap(this.areas, (area) => [
this.translate('campaign-export.assessment.competence-area.mastery-percentage', { name: area.title }),
this.translate('campaign-export.assessment.competence-area.total-items', { name: area.title }),
this.translate('campaign-export.assessment.competence-area.items-successfully-completed', { name: area.title }),
Expand All @@ -147,6 +148,8 @@ class CampaignAssessmentExport {
targetProfile: this.targetProfile,
additionalHeaders: this.additionalHeaders,
learningContent: this.learningContent,
areas: this.areas,
competences: this.competences,
stageCollection: this.stageCollection,
participantKnowledgeElementsByCompetenceId: await this.#getParticipantKnowledgeElementsByCompetenceId({
campaignParticipationInfo,
Expand Down
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
Loading
Loading