Skip to content

Commit f586d18

Browse files
refactor(api): remove flash campaign code in participant result repository
1 parent 46057be commit f586d18

File tree

6 files changed

+2
-281
lines changed

6 files changed

+2
-281
lines changed

api/lib/infrastructure/repositories/flash-assessment-result-repository.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,4 @@ const save = async function ({ answerId, estimatedLevel, errorRate, assessmentId
1313
});
1414
};
1515

16-
const getLatestByAssessmentId = async function (assessmentId) {
17-
const knexConn = DomainTransaction.getConnection();
18-
return knexConn(TABLE_NAME).where({ assessmentId }).orderBy('id', 'desc').limit(1).first();
19-
};
20-
21-
export { getLatestByAssessmentId, save };
16+
export { save };

api/src/evaluation/domain/services/algorithm-methods/data-fetcher.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,10 @@ async function fetchForCompetenceEvaluations({
8888
};
8989
}
9090

91-
async function fetchForFlashCampaigns({
92-
assessmentId,
93-
answerRepository,
94-
challengeRepository,
95-
flashAssessmentResultRepository,
96-
locale,
97-
}) {
91+
async function fetchForFlashCampaigns({ assessmentId, answerRepository, challengeRepository, locale }) {
9892
const [allAnswers, challenges, { estimatedLevel } = {}] = await Promise.all([
9993
answerRepository.findByAssessment(assessmentId),
10094
challengeRepository.findActiveFlashCompatible({ locale }),
101-
flashAssessmentResultRepository.getLatestByAssessmentId(assessmentId),
10295
]);
10396

10497
const challengeIds = new Set(challenges.map(({ id }) => id));

api/src/prescription/campaign-participation/infrastructure/repositories/participant-result-repository.js

-47
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import _ from 'lodash';
22

33
import { knex } from '../../../../../db/knex-database-connection.js';
4-
import * as flashAssessmentResultRepository from '../../../../../lib/infrastructure/repositories/flash-assessment-result-repository.js';
5-
import * as flash from '../../../../certification/flash-certification/domain/services/algorithm-methods/flash.js';
6-
import * as dataFetcher from '../../../../evaluation/domain/services/algorithm-methods/data-fetcher.js';
74
import { convertLevelStagesIntoThresholds } from '../../../../evaluation/domain/services/stages/convert-level-stages-into-thresholds-service.js';
85
import { NotFoundError } from '../../../../shared/domain/errors.js';
96
import { Assessment } from '../../../../shared/domain/models/index.js';
107
import { AssessmentResult } from '../../../../shared/domain/read-models/participant-results/AssessmentResult.js';
11-
import * as answerRepository from '../../../../shared/infrastructure/repositories/answer-repository.js';
128
import * as areaRepository from '../../../../shared/infrastructure/repositories/area-repository.js';
13-
import * as challengeRepository from '../../../../shared/infrastructure/repositories/challenge-repository.js';
149
import * as competenceRepository from '../../../../shared/infrastructure/repositories/competence-repository.js';
1510
import { repositories as sharedInjectedRepositories } from '../../../../shared/infrastructure/repositories/index.js';
1611
import * as skillRepository from '../../../../shared/infrastructure/repositories/skill-repository.js';
@@ -36,9 +31,6 @@ import * as campaignRepository from '../../../campaign/infrastructure/repositori
3631
const get = async function ({ userId, campaignId, badges, reachedStage, stages, locale }) {
3732
const participationResults = await _getParticipationResults(userId, campaignId, locale);
3833
let flashScoringResults;
39-
if (participationResults.isFlash) {
40-
flashScoringResults = await _getFlashScoringResults(participationResults.assessmentId, locale);
41-
}
4234
const campaignDTO = await _getCampaignDTO(campaignId);
4335
const isCampaignMultipleSendings = _isCampaignMultipleSendings(campaignDTO);
4436
const isCampaignArchived = _isCampaignArchived(campaignDTO);
@@ -109,45 +101,6 @@ async function _getParticipationResults(userId, campaignId) {
109101
};
110102
}
111103

112-
async function _getFlashScoringResults(assessmentId, locale) {
113-
const { allAnswers, challenges, estimatedLevel } = await dataFetcher.fetchForFlashCampaigns({
114-
assessmentId,
115-
locale,
116-
answerRepository,
117-
challengeRepository,
118-
flashAssessmentResultRepository,
119-
});
120-
121-
const { pixScore, pixScoreByCompetence } = flash.calculateTotalPixScoreAndScoreByCompetence({
122-
allAnswers,
123-
challenges,
124-
capacity: estimatedLevel,
125-
});
126-
127-
const competences = await competenceRepository.findByRecordIds({
128-
competenceIds: pixScoreByCompetence.map(({ competenceId }) => competenceId),
129-
locale,
130-
});
131-
132-
const areas = await areaRepository.list({ locale });
133-
134-
const competencesWithPixScore = _.sortBy(
135-
pixScoreByCompetence.map(({ competenceId, pixScore }) => {
136-
const competence = competences.find(({ id }) => id === competenceId);
137-
const area = areas.find(({ id }) => id === competence.areaId);
138-
139-
return {
140-
competence,
141-
area,
142-
pixScore,
143-
};
144-
}),
145-
'competence.index',
146-
);
147-
148-
return { estimatedLevel, pixScore, competencesWithPixScore };
149-
}
150-
151104
async function _getParticipationAttributes(userId, campaignId) {
152105
const participationAttributes = await knex('campaign-participations')
153106
.select([

api/tests/evaluation/unit/domain/services/smart-random/data-fetcher_test.js

-83
Original file line numberDiff line numberDiff line change
@@ -152,89 +152,6 @@ describe('Unit | Domain | services | smart-random | dataFetcher', function () {
152152
});
153153
});
154154

155-
describe('#fetchForFlashCampaigns', function () {
156-
let answerRepository;
157-
let challengeRepository;
158-
let flashAssessmentResultRepository;
159-
160-
beforeEach(function () {
161-
answerRepository = {
162-
findByAssessment: sinon.stub(),
163-
};
164-
challengeRepository = {
165-
findActiveFlashCompatible: sinon.stub(),
166-
getMany: sinon.stub(),
167-
};
168-
flashAssessmentResultRepository = {
169-
getLatestByAssessmentId: sinon.stub(),
170-
};
171-
});
172-
173-
it('fetches answers, challenges and lastest estimated level', async function () {
174-
// given
175-
const { id: assessmentId } = domainBuilder.buildAssessment.ofTypeCampaign({
176-
state: 'started',
177-
method: 'FLASH',
178-
campaignParticipationId: 1,
179-
userId: 5678899,
180-
});
181-
const answers = [{ id: 'answerId', challengeId: 'challengeId' }];
182-
const challenges = [{ id: 'challengeId' }];
183-
const estimatedLevel = Symbol('estimatedLevel');
184-
185-
answerRepository.findByAssessment.withArgs(assessmentId).resolves(answers);
186-
challengeRepository.findActiveFlashCompatible.withArgs().resolves(challenges);
187-
flashAssessmentResultRepository.getLatestByAssessmentId.withArgs(assessmentId).resolves({ estimatedLevel });
188-
189-
// when
190-
const data = await dataFetcher.fetchForFlashCampaigns({
191-
assessmentId,
192-
answerRepository,
193-
challengeRepository,
194-
flashAssessmentResultRepository,
195-
});
196-
197-
// then
198-
expect(data.allAnswers).to.deep.equal(answers);
199-
expect(data.challenges).to.deep.equal(challenges);
200-
expect(data.estimatedLevel).to.equal(estimatedLevel);
201-
});
202-
203-
it('fetches missing challenges corresponding to answers', async function () {
204-
// given
205-
const { id: assessmentId } = domainBuilder.buildAssessment.ofTypeCampaign({
206-
state: 'started',
207-
method: 'FLASH',
208-
campaignParticipationId: 1,
209-
userId: 5678899,
210-
});
211-
const answers = [
212-
{ id: 'answerId1', challengeId: 'challengeId' },
213-
{ id: 'answerId2', challengeId: 'missingChallengeId' },
214-
];
215-
const challenges = [{ id: 'challengeId' }];
216-
const missingChallenges = [{ id: 'missingChallengeId' }];
217-
const expectedChallenges = [...challenges, ...missingChallenges];
218-
const estimatedLevel = Symbol('estimatedLevel');
219-
220-
answerRepository.findByAssessment.withArgs(assessmentId).resolves(answers);
221-
challengeRepository.findActiveFlashCompatible.withArgs().resolves(challenges);
222-
challengeRepository.getMany.withArgs(['missingChallengeId']).resolves(missingChallenges);
223-
flashAssessmentResultRepository.getLatestByAssessmentId.withArgs(assessmentId).resolves({ estimatedLevel });
224-
225-
// when
226-
const data = await dataFetcher.fetchForFlashCampaigns({
227-
assessmentId,
228-
answerRepository,
229-
challengeRepository,
230-
flashAssessmentResultRepository,
231-
});
232-
233-
// then
234-
expect(data.challenges).to.deep.equal(expectedChallenges);
235-
});
236-
});
237-
238155
describe('#fetchForFlashLevelEstimation', function () {
239156
let answerRepository;
240157
let challengeRepository;

api/tests/integration/infrastructure/repositories/flash-assessment-result-repository_test.js

-57
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,6 @@ import * as flashAssessmentResultRepository from '../../../../lib/infrastructure
22
import { databaseBuilder, expect, knex } from '../../../test-helper.js';
33

44
describe('Integration | Infrastructure | Repository | FlashAssessmentResultRepository', function () {
5-
describe('#getLatestByAssessmentId', function () {
6-
let assessmentId;
7-
8-
beforeEach(async function () {
9-
assessmentId = databaseBuilder.factory.buildAssessment({ method: 'FLASH' }).id;
10-
await databaseBuilder.commit();
11-
});
12-
13-
context('when assessment has no assessment results yet', function () {
14-
it('should return undefined', async function () {
15-
// when
16-
const result = await flashAssessmentResultRepository.getLatestByAssessmentId(assessmentId);
17-
18-
// then
19-
expect(result).to.be.undefined;
20-
});
21-
});
22-
23-
context('when assessment has several assessment results', function () {
24-
let expectedResult;
25-
26-
beforeEach(async function () {
27-
expectedResult = databaseBuilder.factory.buildFlashAssessmentResult({
28-
id: 125,
29-
estimatedLevel: 1,
30-
errorRate: 2,
31-
assessmentId,
32-
});
33-
databaseBuilder.factory.buildFlashAssessmentResult({
34-
id: 124,
35-
estimatedLevel: 3,
36-
errorRate: 4,
37-
assessmentId,
38-
});
39-
databaseBuilder.factory.buildFlashAssessmentResult({
40-
id: 123,
41-
estimatedLevel: 5,
42-
errorRate: 6,
43-
assessmentId,
44-
});
45-
await databaseBuilder.commit();
46-
});
47-
48-
it('should return the latest flash result', async function () {
49-
// when
50-
const result = await flashAssessmentResultRepository.getLatestByAssessmentId(assessmentId);
51-
52-
// then
53-
expect(result).to.contain({
54-
id: expectedResult.id,
55-
estimatedLevel: expectedResult.estimatedLevel,
56-
errorRate: expectedResult.errorRate,
57-
});
58-
});
59-
});
60-
});
61-
625
describe('#save', function () {
636
it('should create a result with estimated level and error rate', async function () {
647
// given

api/tests/prescription/campaign-participation/integration/infrastructure/repositories/participant-result-repository_test.js

-80
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as participantResultRepository from '../../../../../../src/prescription
22
import { KnowledgeElementCollection } from '../../../../../../src/prescription/shared/domain/models/KnowledgeElementCollection.js';
33
import { NotFoundError } from '../../../../../../src/shared/domain/errors.js';
44
import {
5-
Assessment,
65
CampaignParticipationStatuses,
76
CampaignTypes,
87
KnowledgeElement,
@@ -488,85 +487,6 @@ describe('Integration | Repository | ParticipantResultRepository', function () {
488487
});
489488
});
490489

491-
context('when campaign is flash', function () {
492-
it('returns the estimated flash level and calculated pix score (total and by competence)', async function () {
493-
// given
494-
const { id: userId } = databaseBuilder.factory.buildUser();
495-
const { id: campaignId } = databaseBuilder.factory.buildCampaign({
496-
assessmentMethod: Assessment.methods.FLASH,
497-
});
498-
const { id: campaignParticipationId } = databaseBuilder.factory.buildCampaignParticipation({
499-
userId,
500-
campaignId,
501-
});
502-
const { id: assessmentId } = databaseBuilder.factory.buildAssessment({
503-
campaignParticipationId,
504-
userId,
505-
method: Assessment.methods.FLASH,
506-
});
507-
const answers = [
508-
databaseBuilder.factory.buildAnswer({
509-
assessmentId,
510-
challengeId: 'challenge1',
511-
result: 'ok',
512-
}),
513-
];
514-
const { estimatedLevel } = databaseBuilder.factory.buildFlashAssessmentResult({
515-
assessmentId,
516-
answerId: answers[0].id,
517-
});
518-
await databaseBuilder.commit();
519-
520-
// when
521-
const participantResult = await participantResultRepository.get({
522-
userId,
523-
campaignId,
524-
targetProfile,
525-
badges: [],
526-
locale: 'FR',
527-
});
528-
529-
// then
530-
expect(participantResult).to.contain({
531-
estimatedFlashLevel: estimatedLevel,
532-
flashPixScore: 202,
533-
});
534-
535-
expect(participantResult.competenceResults).to.deep.equal([
536-
{
537-
id: 'rec1',
538-
name: 'comp1Fr',
539-
index: '1.1',
540-
areaName: 'area1',
541-
description: "Teste les qualités de l'utilisateur",
542-
areaTitle: 'domaine1',
543-
areaColor: 'colorArea1',
544-
testedSkillsCount: 0,
545-
totalSkillsCount: 2,
546-
validatedSkillsCount: 0,
547-
masteryPercentage: 0,
548-
reachedStage: undefined,
549-
flashPixScore: 2,
550-
},
551-
{
552-
id: 'rec2',
553-
name: 'comp2Fr',
554-
index: '2.1',
555-
areaName: 'area2',
556-
areaTitle: 'domaine2',
557-
description: "Teste les qualités de l'utilisateur",
558-
areaColor: 'colorArea2',
559-
testedSkillsCount: 0,
560-
totalSkillsCount: 3,
561-
validatedSkillsCount: 0,
562-
masteryPercentage: 0,
563-
reachedStage: undefined,
564-
flashPixScore: 200,
565-
},
566-
]);
567-
});
568-
});
569-
570490
context('when there are several participations', function () {
571491
it('use the participation not improved yet', async function () {
572492
const { id: userId } = databaseBuilder.factory.buildUser();

0 commit comments

Comments
 (0)