From 7b9e5783a5ecbe6c2de3400a7b62493b1827bf5c Mon Sep 17 00:00:00 2001 From: alicegoarnisson Date: Wed, 5 Feb 2025 12:08:25 +0100 Subject: [PATCH] tech(api): replacing userId sharedAt combo in findMultipleUsersFromUserIdsAndSnappedAtDates wip --- .../prod/compute-participation-results.js | 6 +- ...ection-participation-summary-repository.js | 6 +- .../knowledge-element-snapshot-repository.js | 38 +++--- .../csv/campaign-assessment-export.js | 13 +- .../campaign-profiles-collection-export.js | 10 +- ...nParticipationKnowledgeElementSnapshots.js | 4 +- .../services/placement-profile-service.js | 30 +++-- .../compute-participation-results_test.js | 1 + ...files-collection-results-to-stream_test.js | 114 ++++++++++++------ ...n-participation-summary-repository_test.js | 1 + ...wledge-element-snapshot-repository_test.js | 42 +------ .../placement-profile-service_test.js | 20 ++- 12 files changed, 144 insertions(+), 141 deletions(-) diff --git a/api/scripts/prod/compute-participation-results.js b/api/scripts/prod/compute-participation-results.js index 5364f298003..c2dcb04a421 100644 --- a/api/scripts/prod/compute-participation-results.js +++ b/api/scripts/prod/compute-participation-results.js @@ -104,11 +104,11 @@ async function _getCampaignParticipationChunks(campaign) { async function _computeResults(skillIds, competences, campaignParticipations) { const knowledgeElementByUser = await _getKnowledgeElementsByUser(campaignParticipations); - const userIdsAndDates = campaignParticipations.map(({ userId, sharedAt }) => { - return { userId, sharedAt }; + const participationInfos = campaignParticipations.map(({ userId, sharedAt, id }) => { + return { userId, sharedAt, campaignParticipationId: id }; }); const placementProfiles = await placementProfileService.getPlacementProfilesWithSnapshotting({ - userIdsAndDates, + participationInfos, competences, allowExcessPixAndLevels: false, }); diff --git a/api/src/prescription/campaign/infrastructure/repositories/campaign-profiles-collection-participation-summary-repository.js b/api/src/prescription/campaign/infrastructure/repositories/campaign-profiles-collection-participation-summary-repository.js index ea496db2910..fddf71938d2 100644 --- a/api/src/prescription/campaign/infrastructure/repositories/campaign-profiles-collection-participation-summary-repository.js +++ b/api/src/prescription/campaign/infrastructure/repositories/campaign-profiles-collection-participation-summary-repository.js @@ -116,12 +116,12 @@ async function _makeMemoizedGetPlacementProfileForUser(results) { const sharedResultsChunks = await PromiseUtils.mapSeries( chunk(sharedResults, CHUNK_SIZE_CAMPAIGN_RESULT_PROCESSING), (sharedResultsChunk) => { - const userIdsAndDates = sharedResultsChunk.map(({ userId, sharedAt }) => { - return { userId, sharedAt }; + const participationInfos = sharedResultsChunk.map(({ campaignParticipationId, userId, sharedAt }) => { + return { campaignParticipationId, userId, sharedAt }; }); return placementProfileService.getPlacementProfilesWithSnapshotting({ - userIdsAndDates, + participationInfos, allowExcessPixAndLevels: false, competences, }); diff --git a/api/src/prescription/campaign/infrastructure/repositories/knowledge-element-snapshot-repository.js b/api/src/prescription/campaign/infrastructure/repositories/knowledge-element-snapshot-repository.js index 30a3d6ece87..b00bf5fcd51 100644 --- a/api/src/prescription/campaign/infrastructure/repositories/knowledge-element-snapshot-repository.js +++ b/api/src/prescription/campaign/infrastructure/repositories/knowledge-element-snapshot-repository.js @@ -68,31 +68,23 @@ const findByUserIdsAndSnappedAtDates = async function (userIdsAndSnappedAtDates /** * @function - * @name findMultipleUsersFromUserIdsAndSnappedAtDates + * @name findCampaignParticipationKnowledgeElementSnapshots * - * @param {Array} userIdsAndSnappedAtDates + * @param {number[]} campaignParticipationIds * @returns {Promise>} */ -const findMultipleUsersFromUserIdsAndSnappedAtDates = async function (userIdsAndSnappedAtDates) { - const params = userIdsAndSnappedAtDates.map((userIdAndDate) => { - return [userIdAndDate.userId, userIdAndDate.sharedAt]; - }); - - const results = await knex - .select('userId', 'snapshot', 'snappedAt', 'campaignParticipationId') - .from('knowledge-element-snapshots') - .whereIn(['knowledge-element-snapshots.userId', 'snappedAt'], params); - - return results.map((result) => { - const mappedKnowledgeElements = _toKnowledgeElementCollection({ snapshot: result.snapshot }); - - return new CampaignParticipationKnowledgeElementSnapshots({ - userId: result.userId, - snappedAt: result.snappedAt, - knowledgeElements: mappedKnowledgeElements, - campaignParticipationId: result.campaignParticipationId, - }); - }); +const findCampaignParticipationKnowledgeElementSnapshots = async function (campaignParticipationIds) { + const knowledgeElementsByCampaignParticipation = await findByCampaignParticipationIds(campaignParticipationIds); + const knowledgeElementsList = []; + campaignParticipationIds.map((campaignParticipationId) => + knowledgeElementsList.push( + new CampaignParticipationKnowledgeElementSnapshots({ + knowledgeElements: knowledgeElementsByCampaignParticipation[campaignParticipationId], + campaignParticipationId: campaignParticipationId, + }), + ), + ); + return knowledgeElementsList; }; /** @@ -119,6 +111,6 @@ const findByCampaignParticipationIds = async function (campaignParticipationIds) export { findByCampaignParticipationIds, findByUserIdsAndSnappedAtDates, - findMultipleUsersFromUserIdsAndSnappedAtDates, + findCampaignParticipationKnowledgeElementSnapshots, save, }; diff --git a/api/src/prescription/campaign/infrastructure/serializers/csv/campaign-assessment-export.js b/api/src/prescription/campaign/infrastructure/serializers/csv/campaign-assessment-export.js index aab77ced4e9..9f2aa84240b 100644 --- a/api/src/prescription/campaign/infrastructure/serializers/csv/campaign-assessment-export.js +++ b/api/src/prescription/campaign/infrastructure/serializers/csv/campaign-assessment-export.js @@ -176,17 +176,16 @@ class CampaignAssessmentExport { let participantKnowledgeElementsByCompetenceId = []; if (campaignParticipationInfo.isShared) { const sharedKnowledgeElementsByUserIdAndCompetenceId = - await knowledgeElementSnapshotRepository.findMultipleUsersFromUserIdsAndSnappedAtDates( - sharedParticipations.map(({ userId, sharedAt }) => ({ userId, sharedAt })), + await knowledgeElementSnapshotRepository.findCampaignParticipationKnowledgeElementSnapshots( + sharedParticipations.map(({ campaignParticipationId }) => campaignParticipationId), ); const sharedResultInfo = sharedKnowledgeElementsByUserIdAndCompetenceId.find( (knowledElementForSharedParticipation) => { - const sameUserId = campaignParticipationInfo.userId === knowledElementForSharedParticipation.userId; - const sameDate = - campaignParticipationInfo.sharedAt && - campaignParticipationInfo.sharedAt.getTime() === knowledElementForSharedParticipation.snappedAt.getTime(); + const sameParticipationId = + campaignParticipationInfo.campaignParticipationId === + knowledElementForSharedParticipation.campaignParticipationId; - return sameUserId && sameDate; + return sameParticipationId; }, ); diff --git a/api/src/prescription/campaign/infrastructure/serializers/csv/campaign-profiles-collection-export.js b/api/src/prescription/campaign/infrastructure/serializers/csv/campaign-profiles-collection-export.js index 37c240c394e..d49eb270a6c 100644 --- a/api/src/prescription/campaign/infrastructure/serializers/csv/campaign-profiles-collection-export.js +++ b/api/src/prescription/campaign/infrastructure/serializers/csv/campaign-profiles-collection-export.js @@ -80,12 +80,14 @@ class CampaignProfilesCollectionExport { } async _getUsersPlacementProfiles(campaignParticipationResultDataChunk, placementProfileService) { - const userIdsAndDates = campaignParticipationResultDataChunk.map(({ userId, sharedAt }) => { - return { userId, sharedAt }; - }); + const participationInfos = campaignParticipationResultDataChunk.map( + ({ id: campaignParticipationId, userId, sharedAt }) => { + return { campaignParticipationId, userId, sharedAt }; + }, + ); const placementProfiles = await placementProfileService.getPlacementProfilesWithSnapshotting({ - userIdsAndDates, + participationInfos, competences: this.competences, allowExcessPixAndLevels: false, }); diff --git a/api/src/prescription/shared/domain/read-models/CampaignParticipationKnowledgeElementSnapshots.js b/api/src/prescription/shared/domain/read-models/CampaignParticipationKnowledgeElementSnapshots.js index 3fa415ad361..142b90135e2 100644 --- a/api/src/prescription/shared/domain/read-models/CampaignParticipationKnowledgeElementSnapshots.js +++ b/api/src/prescription/shared/domain/read-models/CampaignParticipationKnowledgeElementSnapshots.js @@ -1,7 +1,5 @@ class CampaignParticipationKnowledgeElementSnapshots { - constructor({ userId, snappedAt, knowledgeElements, campaignParticipationId } = {}) { - this.userId = userId; - this.snappedAt = snappedAt; + constructor({ knowledgeElements, campaignParticipationId } = {}) { this.knowledgeElements = knowledgeElements; this.campaignParticipationId = campaignParticipationId; } diff --git a/api/src/shared/domain/services/placement-profile-service.js b/api/src/shared/domain/services/placement-profile-service.js index 81916034756..609b64c141d 100644 --- a/api/src/shared/domain/services/placement-profile-service.js +++ b/api/src/shared/domain/services/placement-profile-service.js @@ -130,19 +130,25 @@ async function _generatePlacementProfile({ userId, profileDate, competences, all }); } -async function getPlacementProfilesWithSnapshotting({ userIdsAndDates, competences, allowExcessPixAndLevels = true }) { - const knowledgeElementsByUserIdAndDates = - await knowledgeElementSnapshotRepository.findMultipleUsersFromUserIdsAndSnappedAtDates(userIdsAndDates); - - return userIdsAndDates.map(({ userId, sharedAt }) => { - const keForUser = knowledgeElementsByUserIdAndDates.find((knowledgeElementsByUserIdAndDates) => { - const sameUserId = knowledgeElementsByUserIdAndDates.userId === userId; - const sameDate = sharedAt && knowledgeElementsByUserIdAndDates.snappedAt.getTime() === sharedAt.getTime(); +async function getPlacementProfilesWithSnapshotting({ + participationInfos, + competences, + allowExcessPixAndLevels = true, +}) { + const campaignParticipationIds = participationInfos.map(({ campaignParticipationId }) => campaignParticipationId); + const knowledgeElementsParticipations = + await knowledgeElementSnapshotRepository.findCampaignParticipationKnowledgeElementSnapshots( + campaignParticipationIds, + ); - return sameUserId && sameDate; + return participationInfos.map((participationInfos) => { + const keForParticipation = knowledgeElementsParticipations.find((knowledgeElementsParticipation) => { + return knowledgeElementsParticipation.campaignParticipationId === participationInfos.campaignParticipationId; }); - const knowledgeElementsByCompetence = keForUser ? _.groupBy(keForUser.knowledgeElements, 'competenceId') : []; + const knowledgeElementsByCompetence = keForParticipation + ? _.groupBy(keForParticipation.knowledgeElements, 'competenceId') + : []; const userCompetences = _createUserCompetencesV2({ knowledgeElementsByCompetence, @@ -151,8 +157,8 @@ async function getPlacementProfilesWithSnapshotting({ userIdsAndDates, competenc }); return new PlacementProfile({ - userId, - profileDate: sharedAt, + userId: participationInfos.userId, + profileDate: participationInfos.sharedAt, userCompetences, }); }); diff --git a/api/tests/integration/scripts/prod/compute-participation-results_test.js b/api/tests/integration/scripts/prod/compute-participation-results_test.js index 0417f9d4ce1..0fc9f3d7ba7 100644 --- a/api/tests/integration/scripts/prod/compute-participation-results_test.js +++ b/api/tests/integration/scripts/prod/compute-participation-results_test.js @@ -253,6 +253,7 @@ function _buildParticipationWithSnapshot(participationAttributes, knowledgeEleme userId: participation.userId, snappedAt: participation.sharedAt, knowledgeElementsAttributes, + campaignParticipationId: participation.id, }); return participation; diff --git a/api/tests/prescription/campaign/integration/domain/usecases/start-writing-campaign-profiles-collection-results-to-stream_test.js b/api/tests/prescription/campaign/integration/domain/usecases/start-writing-campaign-profiles-collection-results-to-stream_test.js index 40d956f9ec7..332438d0b21 100644 --- a/api/tests/prescription/campaign/integration/domain/usecases/start-writing-campaign-profiles-collection-results-to-stream_test.js +++ b/api/tests/prescription/campaign/integration/domain/usecases/start-writing-campaign-profiles-collection-results-to-stream_test.js @@ -32,6 +32,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c let writableStream; let csvPromise; let i18n; + let ke1, ke2, ke3, ke4, ke5; const createdAt = new Date('2019-02-25T10:00:00Z'); const sharedAt = new Date('2019-03-01T23:04:05Z'); @@ -49,7 +50,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c participant = databaseBuilder.factory.buildUser(); - const ke1 = databaseBuilder.factory.buildKnowledgeElement({ + ke1 = databaseBuilder.factory.buildKnowledgeElement({ status: 'validated', pixScore: 2, skillId: skillWeb1.id, @@ -58,7 +59,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c userId: participant.id, createdAt, }); - const ke2 = databaseBuilder.factory.buildKnowledgeElement({ + ke2 = databaseBuilder.factory.buildKnowledgeElement({ status: 'validated', pixScore: 2, skillId: skillWeb2.id, @@ -67,7 +68,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c userId: participant.id, createdAt, }); - const ke3 = databaseBuilder.factory.buildKnowledgeElement({ + ke3 = databaseBuilder.factory.buildKnowledgeElement({ status: 'invalidated', pixScore: 2, skillId: skillWeb3.id, @@ -76,7 +77,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c userId: participant.id, createdAt, }); - const ke4 = databaseBuilder.factory.buildKnowledgeElement({ + ke4 = databaseBuilder.factory.buildKnowledgeElement({ status: 'validated', skillId: skillUrl1.id, earnedPix: 2, @@ -84,7 +85,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c userId: participant.id, createdAt, }); - const ke5 = databaseBuilder.factory.buildKnowledgeElement({ + ke5 = databaseBuilder.factory.buildKnowledgeElement({ status: 'validated', skillId: skillUrl8.id, earnedPix: 64, @@ -93,12 +94,6 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c createdAt, }); - databaseBuilder.factory.buildKnowledgeElementSnapshot({ - userId: participant.id, - snappedAt: sharedAt, - snapshot: JSON.stringify([ke1, ke2, ke3, ke4, ke5]), - }); - databaseBuilder.factory.learningContent.buildFramework({ id: 'recFramework', }); @@ -156,15 +151,18 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c }); organizationLearner = { firstName: '@Jean', lastName: '=Bono' }; - databaseBuilder.factory.buildCampaignParticipationWithOrganizationLearner(organizationLearner, { - createdAt, - sharedAt, - status: CampaignParticipationStatuses.SHARED, - campaignId: campaign.id, - userId: participant.id, - pixScore: 52, - isImproved: true, - }); + const participationShared = databaseBuilder.factory.buildCampaignParticipationWithOrganizationLearner( + organizationLearner, + { + createdAt, + sharedAt, + status: CampaignParticipationStatuses.SHARED, + campaignId: campaign.id, + userId: participant.id, + pixScore: 52, + isImproved: true, + }, + ); databaseBuilder.factory.buildCampaignParticipationWithOrganizationLearner(organizationLearner, { createdAt, @@ -176,6 +174,13 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c isImproved: false, }); + databaseBuilder.factory.buildKnowledgeElementSnapshot({ + userId: participationShared.userId, + snappedAt: participationShared.sharedAt, + snapshot: JSON.stringify([ke1, ke2, ke3, ke4, ke5]), + campaignParticipationId: participationShared.id, + }); + await databaseBuilder.commit(); }); @@ -228,15 +233,25 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c }); organizationLearner = { firstName: '@Jean', lastName: '=Bono' }; - databaseBuilder.factory.buildCampaignParticipationWithOrganizationLearner(organizationLearner, { - createdAt, - sharedAt, - status: CampaignParticipationStatuses.SHARED, - participantExternalId: '+Mon mail pro', - campaignId: campaign.id, - userId: participant.id, - pixScore: 52, - isImproved: true, + const participationShared = databaseBuilder.factory.buildCampaignParticipationWithOrganizationLearner( + organizationLearner, + { + createdAt, + sharedAt, + status: CampaignParticipationStatuses.SHARED, + participantExternalId: '+Mon mail pro', + campaignId: campaign.id, + userId: participant.id, + pixScore: 52, + isImproved: true, + }, + ); + + databaseBuilder.factory.buildKnowledgeElementSnapshot({ + userId: participationShared.userId, + snappedAt: participationShared.sharedAt, + snapshot: JSON.stringify([ke1, ke2, ke3, ke4, ke5]), + campaignParticipationId: participationShared.id, }); await databaseBuilder.commit(); @@ -370,14 +385,23 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c }); organizationLearner = { firstName: '@Jean', lastName: '=Bono' }; - databaseBuilder.factory.buildCampaignParticipationWithOrganizationLearner(organizationLearner, { - createdAt, - sharedAt, - campaignId: campaign.id, - userId: participant.id, - pixScore: 52, - }); + const participationShared = databaseBuilder.factory.buildCampaignParticipationWithOrganizationLearner( + organizationLearner, + { + createdAt, + sharedAt, + campaignId: campaign.id, + userId: participant.id, + pixScore: 52, + }, + ); + databaseBuilder.factory.buildKnowledgeElementSnapshot({ + userId: participationShared.userId, + snappedAt: participationShared.sharedAt, + snapshot: JSON.stringify([ke1, ke2, ke3, ke4, ke5]), + campaignParticipationId: participationShared.id, + }); await databaseBuilder.commit(); }); @@ -446,7 +470,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c title: null, }); - databaseBuilder.factory.buildCampaignParticipation({ + const participationShared = databaseBuilder.factory.buildCampaignParticipation({ createdAt, sharedAt, campaignId: campaign.id, @@ -455,6 +479,13 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c pixScore: 52, }); + databaseBuilder.factory.buildKnowledgeElementSnapshot({ + userId: participationShared.userId, + snappedAt: participationShared.sharedAt, + snapshot: JSON.stringify([ke1, ke2, ke3, ke4, ke5]), + campaignParticipationId: participationShared.id, + }); + await databaseBuilder.commit(); }); @@ -525,7 +556,7 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c title: null, }); - databaseBuilder.factory.buildCampaignParticipation({ + const participationShared = databaseBuilder.factory.buildCampaignParticipation({ createdAt, sharedAt, campaignId: campaign.id, @@ -534,6 +565,13 @@ describe('Integration | Domain | Use Cases | start-writing-profiles-collection-c pixScore: 52, }); + databaseBuilder.factory.buildKnowledgeElementSnapshot({ + userId: participationShared.userId, + snappedAt: participationShared.sharedAt, + snapshot: JSON.stringify([ke1, ke2, ke3, ke4, ke5]), + campaignParticipationId: participationShared.id, + }); + await databaseBuilder.commit(); }); diff --git a/api/tests/prescription/campaign/integration/infrastructure/repositories/campaign-profiles-collection-participation-summary-repository_test.js b/api/tests/prescription/campaign/integration/infrastructure/repositories/campaign-profiles-collection-participation-summary-repository_test.js index 0d39edf8dd5..85f122251cb 100644 --- a/api/tests/prescription/campaign/integration/infrastructure/repositories/campaign-profiles-collection-participation-summary-repository_test.js +++ b/api/tests/prescription/campaign/integration/infrastructure/repositories/campaign-profiles-collection-participation-summary-repository_test.js @@ -172,6 +172,7 @@ describe('Integration | Repository | Campaign Profiles Collection Participation userId: campaignParticipation.userId, snappedAt: campaignParticipation.sharedAt, snapshot: JSON.stringify([ke1, ke2]), + campaignParticipationId: campaignParticipation.id, }); await databaseBuilder.commit(); diff --git a/api/tests/prescription/campaign/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js b/api/tests/prescription/campaign/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js index c807408fad4..ed4f857c85c 100644 --- a/api/tests/prescription/campaign/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js +++ b/api/tests/prescription/campaign/integration/infrastructure/repositories/knowledge-element-snapshot-repository_test.js @@ -270,7 +270,7 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi }); }); - describe('#findMultipleUsersFromUserIdsAndSnappedAtDates', function () { + describe('#findCampaignParticipationKnowledgeElementSnapshots', function () { let userId1, userId2; let snappedAt1, snappedAt2, snappedAt3; let knowledgeElement1, knowledgeElement2, knowledgeElement3; @@ -360,10 +360,10 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi it('should find knowledge elements snapshoted grouped by campaign participation id for given userIds and their respective dates', async function () { // when const knowledgeElementsByUserId = - await knowledgeElementSnapshotRepository.findMultipleUsersFromUserIdsAndSnappedAtDates([ - { userId: userId1, sharedAt: snappedAt1 }, - { userId: userId2, sharedAt: snappedAt2 }, - { userId: userId2, sharedAt: snappedAt3 }, + await knowledgeElementSnapshotRepository.findCampaignParticipationKnowledgeElementSnapshots([ + campaignParticipationId1, + campaignParticipationId2, + campaignParticipationId3, ]); // then @@ -371,50 +371,18 @@ describe('Integration | Repository | KnowledgeElementSnapshotRepository', functi expect(knowledgeElementsByUserId).to.deep.members([ { - userId: userId1, - snappedAt: snappedAt1, knowledgeElements: [knowledgeElement1], campaignParticipationId: campaignParticipationId1, }, { - userId: userId2, - snappedAt: snappedAt2, knowledgeElements: [knowledgeElement2], campaignParticipationId: campaignParticipationId2, }, { - userId: userId2, - snappedAt: snappedAt3, knowledgeElements: [knowledgeElement3], campaignParticipationId: campaignParticipationId3, }, ]); }); - - it('should return empty list of snapshoted knowledge elements given unmatching dates', async function () { - // when - const snappedAt = new Date('2023-02-01'); - const knowledgeElementsByUserId = - await knowledgeElementSnapshotRepository.findMultipleUsersFromUserIdsAndSnappedAtDates([ - { userId: userId1, sharedAt: snappedAt }, - ]); - - // then - expect(knowledgeElementsByUserId).lengthOf(0); - }); - - it('should return empty list of snapshoted knowledge elements given unmatching userId', async function () { - const userId = databaseBuilder.factory.buildUser().id; - - await databaseBuilder.commit(); - // when - const knowledgeElementsByUserId = - await knowledgeElementSnapshotRepository.findMultipleUsersFromUserIdsAndSnappedAtDates([ - { userId, sharedAt: snappedAt1 }, - ]); - - // then - expect(knowledgeElementsByUserId).lengthOf(0); - }); }); }); diff --git a/api/tests/shared/integration/domain/services/placement-profile-service_test.js b/api/tests/shared/integration/domain/services/placement-profile-service_test.js index be91747e377..17b01f9ab53 100644 --- a/api/tests/shared/integration/domain/services/placement-profile-service_test.js +++ b/api/tests/shared/integration/domain/services/placement-profile-service_test.js @@ -477,7 +477,7 @@ describe('Shared | Integration | Domain | Services | Placement Profile Service', it('should assign 0 pixScore and level of 0 to user competence when not assessed', async function () { // when const actualPlacementProfiles = await placementProfileService.getPlacementProfilesWithSnapshotting({ - userIdsAndDates: [{ userId, sharedAt: new Date() }], + participationInfos: [{ campaignParticipationId: campaignParticipation.id }], competences, }); @@ -530,13 +530,14 @@ describe('Shared | Integration | Domain | Services | Placement Profile Service', userId: userId, snappedAt: sharedAt, snapshot: JSON.stringify([ke]), + campaignParticipationId: campaignParticipation.id, }); await databaseBuilder.commit(); // when const actualPlacementProfiles = await placementProfileService.getPlacementProfilesWithSnapshotting({ - userIdsAndDates: [{ userId, sharedAt }], + participationInfos: [{ campaignParticipationId: campaignParticipation.id }], competences, }); @@ -580,12 +581,13 @@ describe('Shared | Integration | Domain | Services | Placement Profile Service', userId: userId, snappedAt: sharedAt, snapshot: JSON.stringify([ke1, ke2]), + campaignParticipationId: campaignParticipation.id, }); await databaseBuilder.commit(); // when const actualPlacementProfiles = await placementProfileService.getPlacementProfilesWithSnapshotting({ - userIdsAndDates: [{ userId, sharedAt }], + participationInfos: [{ campaignParticipationId: campaignParticipation.id }], competences, }); @@ -595,7 +597,6 @@ describe('Shared | Integration | Domain | Services | Placement Profile Service', context('when we dont want to limit pix score', function () { it('should not limit pixScore and level to the max reachable for user competence based on knowledge elements', async function () { - const sharedAt = new Date('2022-01-05'); const ke = databaseBuilder.factory.buildKnowledgeElement({ competenceId: 'competenceRecordIdOne', earnedPix: 64, @@ -605,16 +606,15 @@ describe('Shared | Integration | Domain | Services | Placement Profile Service', }); databaseBuilder.factory.buildKnowledgeElementSnapshot({ - userId: userId, - snappedAt: sharedAt, snapshot: JSON.stringify([ke]), + campaignParticipationId: campaignParticipation.id, }); await databaseBuilder.commit(); // when const actualPlacementProfiles = await placementProfileService.getPlacementProfilesWithSnapshotting({ - userIdsAndDates: [{ userId, sharedAt }], + participationInfos: [{ campaignParticipationId: campaignParticipation.id }], competences, allowExcessPixAndLevels: true, }); @@ -630,7 +630,6 @@ describe('Shared | Integration | Domain | Services | Placement Profile Service', context('when we want to limit pix score', function () { it('should limit pixScore to 40 and level to 5', async function () { - const sharedAt = new Date('2022-01-05'); const ke = databaseBuilder.factory.buildKnowledgeElement({ competenceId: 'competenceRecordIdOne', earnedPix: 64, @@ -640,8 +639,7 @@ describe('Shared | Integration | Domain | Services | Placement Profile Service', }); databaseBuilder.factory.buildKnowledgeElementSnapshot({ - userId: userId, - snappedAt: sharedAt, + campaignParticipationId: campaignParticipation.id, snapshot: JSON.stringify([ke]), }); @@ -649,7 +647,7 @@ describe('Shared | Integration | Domain | Services | Placement Profile Service', // when const actualPlacementProfiles = await placementProfileService.getPlacementProfilesWithSnapshotting({ - userIdsAndDates: [{ userId, sharedAt }], + participationInfos: [{ campaignParticipationId: campaignParticipation.id }], competences, allowExcessPixAndLevels: false, });