Skip to content

Commit

Permalink
[BUGFIX] Récupérer uniquement les compétences sur le référentiel Pix …
Browse files Browse the repository at this point in the history
…Coeur pour le scoring V3 (PIX-16272).

 #11268
  • Loading branch information
pix-service-auto-merge authored Jan 30, 2025
2 parents 7c10c59 + 1e3182f commit b6b08c4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { V3CertificationScoring } from '../../domain/models/V3CertificationScori

export const getLatestByDateAndLocale = async ({ locale, date }) => {
const allAreas = await areaRepository.list();
const competenceList = await competenceRepository.list({ locale });
// NOTE : only works for certification of core competencies
const competenceList = await competenceRepository.listPixCompetencesOnly({ locale });

const competenceScoringConfiguration = await knex('competence-scoring-configurations')
.select('configuration')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import _ from 'lodash';

import { knex } from '../../../../../../db/knex-database-connection.js';
import { V3CertificationScoring } from '../../../../../../src/certification/shared/domain/models/V3CertificationScoring.js';
import {
getLatestByDateAndLocale,
saveCertificationScoringConfiguration,
saveCompetenceForScoringConfiguration,
} from '../../../../../../src/certification/shared/infrastructure/repositories/scoring-configuration-repository.js';
import { PIX_ORIGIN } from '../../../../../../src/shared/domain/constants.js';
import { NotFoundError } from '../../../../../../src/shared/domain/errors.js';
import { catchErr, databaseBuilder, expect, mockLearningContent } from '../../../../../test-helper.js';
import { buildArea, buildCompetence, buildFramework } from '../../../../../tooling/domain-builder/factory/index.js';
import { buildLearningContent } from '../../../../../tooling/learning-content-builder/index.js';
import { catchErr, databaseBuilder, expect } from '../../../../../test-helper.js';

describe('Integration | Repository | scoring-configuration-repository', function () {
describe('#getLatestByDateAndLocale', function () {
beforeEach(async function () {
const userId = databaseBuilder.factory.buildUser().id;
const frameworkId = 'frameworkId';

const competenceScoringConfiguration = [
{
Expand Down Expand Up @@ -44,28 +40,11 @@ describe('Integration | Repository | scoring-configuration-repository', function
const secondConfigurationDate = new Date('2020-01-01T08:00:00Z');
const thirdConfigurationDate = new Date('2021-01-01T08:00:00Z');

const getAreaCode = (competenceCode) => competenceCode.split('.').shift();
const competenceLevelIntervalsWithAreaCode = competenceScoringConfiguration.map((competenceLevelInterval) => ({
...competenceLevelInterval,
areaCode: getAreaCode(competenceLevelInterval.competence),
}));
const competenceLevelIntervalsByArea = _.groupBy(competenceLevelIntervalsWithAreaCode, 'areaCode');
const areas = Object.entries(competenceLevelIntervalsByArea).map(([areaCode, competenceLevelIntervals]) => {
const areaId = `recArea${areaCode}`;

const competences = competenceLevelIntervals.map((competenceLevelInterval) => {
const competenceIndex = competenceLevelInterval.competence;
const competenceId = `recCompetence${competenceIndex}`;

return buildCompetence({ id: competenceId, areaId, index: competenceIndex });
});

return buildArea({ id: areaId, frameworkId, code: areaCode, competences });
});
const framework = buildFramework({ id: frameworkId, name: 'someFramework', areas });
const learningContent = buildLearningContent([framework]);

await mockLearningContent(learningContent);
// Competences exist in multiple frameworks with the same index
// Here, we need to get only competences that are part of the PIX_ORIGIN framework
const competenceIndex = '1.1';
buildFramework({ competenceIndex, origin: 'external' });
buildFramework({ competenceIndex, origin: PIX_ORIGIN });

databaseBuilder.factory.buildCompetenceScoringConfiguration({
configuration: competenceScoringConfiguration,
Expand Down Expand Up @@ -135,7 +114,7 @@ describe('Integration | Repository | scoring-configuration-repository', function
});
});

it('should return a list of competences for scoring', async function () {
it('should return a list of Pix Origin competences for scoring', async function () {
// given
const date = new Date('2020-07-01T08:00:00Z');

Expand All @@ -144,6 +123,7 @@ describe('Integration | Repository | scoring-configuration-repository', function

// then
expect(result).to.be.instanceOf(V3CertificationScoring);
expect(result._competencesForScoring[0].competenceId).to.be.equal(`${PIX_ORIGIN}Competence`);
expect(result._competencesForScoring[0].intervals.length).not.to.be.equal(0);
expect(result._certificationScoringConfiguration[0].bounds.min).to.be.equal(-5.12345);
expect(result._certificationScoringConfiguration[7].bounds.max).to.be.equal(6.56789);
Expand Down Expand Up @@ -188,3 +168,22 @@ describe('Integration | Repository | scoring-configuration-repository', function
});
});
});

function buildFramework({ competenceIndex, origin }) {
const framework = databaseBuilder.factory.learningContent.buildFramework({
id: `${origin}FrameworkId`,
name: `${origin}Framework`,
});
const competence = databaseBuilder.factory.learningContent.buildCompetence({
id: `${origin}Competence`,
index: competenceIndex,
areaId: `${origin}Area`,
origin,
});
databaseBuilder.factory.learningContent.buildArea({
id: `${origin}Area`,
frameworkId: framework.id,
code: '1',
competenceIds: [competence.id],
});
}

0 comments on commit b6b08c4

Please sign in to comment.