From f18071517ab455a363a158e7175f5fae4a4ce3a9 Mon Sep 17 00:00:00 2001 From: alicegoarnisson Date: Fri, 13 Dec 2024 16:16:28 +0100 Subject: [PATCH 1/5] feat(orga): moved usecases and their tests --- ...ed-participation-results-to-pole-emploi.js | 10 +- ...rticipation-results-to-pole-emploi_test.js | 6 +- ...rticipation-results-to-pole-emploi_test.js | 290 ------------------ 3 files changed, 8 insertions(+), 298 deletions(-) rename api/{lib => src/prescription/campaign-participation}/domain/usecases/send-shared-participation-results-to-pole-emploi.js (80%) rename api/tests/{ => prescription/campaign-participation}/integration/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js (90%) delete mode 100644 api/tests/unit/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js diff --git a/api/lib/domain/usecases/send-shared-participation-results-to-pole-emploi.js b/api/src/prescription/campaign-participation/domain/usecases/send-shared-participation-results-to-pole-emploi.js similarity index 80% rename from api/lib/domain/usecases/send-shared-participation-results-to-pole-emploi.js rename to api/src/prescription/campaign-participation/domain/usecases/send-shared-participation-results-to-pole-emploi.js index 294fb74a3f4..0e2f4bc2acb 100644 --- a/api/lib/domain/usecases/send-shared-participation-results-to-pole-emploi.js +++ b/api/src/prescription/campaign-participation/domain/usecases/send-shared-participation-results-to-pole-emploi.js @@ -1,8 +1,8 @@ -import { PoleEmploiSending } from '../../../src/prescription/campaign-participation/domain/models/PoleEmploiSending.js'; -import { PoleEmploiPayload } from '../../../src/prescription/campaign-participation/infrastructure/externals/pole-emploi/PoleEmploiPayload.js'; -import { logger } from '../../../src/shared/infrastructure/utils/logger.js'; -import * as httpErrorsHelper from '../../infrastructure/http/errors-helper.js'; -import { httpAgent } from '../../infrastructure/http/http-agent.js'; +import * as httpErrorsHelper from '../../../../../lib/infrastructure/http/errors-helper.js'; +import { httpAgent } from '../../../../../lib/infrastructure/http/http-agent.js'; +import { logger } from '../../../../shared/infrastructure/utils/logger.js'; +import { PoleEmploiPayload } from '../../infrastructure/externals/pole-emploi/PoleEmploiPayload.js'; +import { PoleEmploiSending } from '../models/PoleEmploiSending.js'; const sendSharedParticipationResultsToPoleEmploi = async ({ campaignParticipationId, diff --git a/api/tests/integration/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js b/api/tests/prescription/campaign-participation/integration/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js similarity index 90% rename from api/tests/integration/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js rename to api/tests/prescription/campaign-participation/integration/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js index 2ea5b3f270c..912e6bf74d5 100644 --- a/api/tests/integration/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js +++ b/api/tests/prescription/campaign-participation/integration/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js @@ -1,5 +1,5 @@ -import { usecases } from '../../../../lib/domain/usecases/index.js'; -import * as poleEmploiNotifier from '../../../../src/prescription/campaign-participation/infrastructure/externals/pole-emploi/pole-emploi-notifier.js'; +import { usecases } from '../../../../../../src/prescription/campaign-participation/domain/usecases/index.js'; +import * as poleEmploiNotifier from '../../../../../../src/prescription/campaign-participation/infrastructure/externals/pole-emploi/pole-emploi-notifier.js'; import { databaseBuilder, expect, @@ -7,7 +7,7 @@ import { learningContentBuilder, mockLearningContent, sinon, -} from '../../../test-helper.js'; +} from '../../../../../test-helper.js'; describe('Integration | Domain | UseCases | send-shared-participation-results-to-pole-emploi', function () { let campaignParticipationId, userId, responseCode; diff --git a/api/tests/unit/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js b/api/tests/unit/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js deleted file mode 100644 index a70b7ceb6b3..00000000000 --- a/api/tests/unit/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js +++ /dev/null @@ -1,290 +0,0 @@ -import { sendSharedParticipationResultsToPoleEmploi } from '../../../../lib/domain/usecases/send-shared-participation-results-to-pole-emploi.js'; -import { PoleEmploiSending } from '../../../../src/prescription/campaign-participation/domain/models/PoleEmploiSending.js'; -import { PoleEmploiPayload } from '../../../../src/prescription/campaign-participation/infrastructure/externals/pole-emploi/PoleEmploiPayload.js'; -import { config } from '../../../../src/shared/config.js'; -import { domainBuilder, expect, sinon } from '../../../test-helper.js'; - -describe('Unit | Domain | UseCase | send-shared-participation-results-to-pole-emploi', function () { - let dependencies, expectedResults; - let campaignRepository, - badgeRepository, - badgeAcquisitionRepository, - campaignParticipationRepository, - campaignParticipationResultRepository, - organizationRepository, - targetProfileRepository, - userRepository, - poleEmploiNotifier, - poleEmploiSendingRepository; - let httpAgent, httpErrorsHelper, logger; - let campaignId, campaignParticipationId, userId, organizationId, badges, badgeAcquiredIds; - let authenticationMethodRepository; - - beforeEach(function () { - httpAgent = Symbol('httpAgent'); - logger = Symbol('logger'); - httpErrorsHelper = Symbol('httpErrorsHelper'); - badgeRepository = { findByCampaignId: sinon.stub() }; - badgeAcquisitionRepository = { getAcquiredBadgeIds: sinon.stub() }; - campaignRepository = { get: sinon.stub() }; - campaignParticipationRepository = { get: sinon.stub() }; - campaignParticipationResultRepository = { getByParticipationId: sinon.stub() }; - organizationRepository = { get: sinon.stub() }; - targetProfileRepository = { get: sinon.stub() }; - userRepository = { get: sinon.stub() }; - poleEmploiNotifier = { notify: sinon.stub() }; - poleEmploiSendingRepository = { create: sinon.stub() }; - authenticationMethodRepository = { - findOneByUserIdAndIdentityProvider: sinon.stub(), - updateAuthenticationComplementByUserIdAndIdentityProvider: sinon.stub(), - }; - - dependencies = { - authenticationMethodRepository, - badgeRepository, - badgeAcquisitionRepository, - campaignRepository, - campaignParticipationRepository, - campaignParticipationResultRepository, - organizationRepository, - poleEmploiSendingRepository, - targetProfileRepository, - userRepository, - poleEmploiNotifier, - notifierDependencies: { - httpAgent, - logger, - httpErrorsHelper, - }, - }; - - expectedResults = new PoleEmploiPayload({ - campagne: { - nom: 'Campagne Pôle Emploi', - dateDebut: new Date('2020-01-01'), - dateFin: new Date('2020-02-01'), - type: 'EVALUATION', - codeCampagne: 'CODEPE123', - urlCampagne: `${config.domain.pixApp + config.domain.tldFr}/campagnes/CODEPE123`, - nomOrganisme: 'Pix', - typeOrganisme: 'externe', - }, - individu: { - nom: 'Bonneau', - prenom: 'Jean', - }, - test: { - etat: 4, - progression: 100, - typeTest: 'DI', - referenceExterne: 55667788, - dateDebut: new Date('2020-01-02'), - dateProgression: new Date('2020-01-03'), - dateValidation: new Date('2020-01-03'), - evaluation: 70, - uniteEvaluation: 'A', - elementsEvalues: [ - { - libelle: 'Gérer des données', - categorie: 'competence', - type: 'competence Pix', - domaineRattachement: 'Information et données', - nbSousElements: 4, - evaluation: { - scoreObtenu: 50, - uniteScore: 'A', - nbSousElementValide: 2, - }, - }, - { - libelle: 'Gérer des données 2', - categorie: 'competence', - type: 'competence Pix', - domaineRattachement: 'Information et données', - nbSousElements: 3, - evaluation: { - scoreObtenu: 100, - uniteScore: 'A', - nbSousElementValide: 3, - }, - }, - ], - }, - badges: [ - { - cle: 1, - titre: 'titre', - message: 'message', - imageUrl: 'imageUrl', - messageAlternatif: 'messageAlternatif', - certifiable: true, - obtenu: true, - }, - ], - }); - badges = [ - { - id: 1, - key: 1, - title: 'titre', - message: 'message', - imageUrl: 'imageUrl', - altMessage: 'messageAlternatif', - isCertifiable: true, - }, - ]; - badgeAcquiredIds = [1]; - campaignId = Symbol('campaignId'); - campaignParticipationId = 55667788; - userId = Symbol('userId'); - organizationId = Symbol('organizationId'); - }); - - context('when campaign is of type ASSESSMENT and organization is Pole Emploi', function () { - beforeEach(function () { - organizationRepository.get.withArgs(organizationId).resolves({ isPoleEmploi: true }); - userRepository.get - .withArgs(userId) - .resolves(domainBuilder.buildUser({ id: userId, firstName: 'Jean', lastName: 'Bonneau' })); - targetProfileRepository.get.withArgs('targetProfileId1').resolves({ name: 'Diagnostic initial' }); - const campaign = domainBuilder.buildCampaign({ - id: campaignId, - name: 'Campagne Pôle Emploi', - code: 'CODEPE123', - createdAt: new Date('2020-01-01'), - archivedAt: new Date('2020-02-01'), - type: 'ASSESSMENT', - targetProfile: { id: 'targetProfileId1' }, - organization: { id: organizationId }, - }); - campaignParticipationRepository.get.withArgs(campaignParticipationId).resolves( - domainBuilder.buildCampaignParticipation({ - id: campaignParticipationId, - campaign, - userId, - sharedAt: new Date('2020-01-03'), - createdAt: new Date('2020-01-02'), - }), - ); - campaignRepository.get.withArgs(campaignId).resolves(campaign); - campaignParticipationResultRepository.getByParticipationId.withArgs(campaignParticipationId).resolves( - domainBuilder.buildCampaignParticipationResult({ - totalSkillsCount: 10, - validatedSkillsCount: 7, - competenceResults: [ - domainBuilder.buildCompetenceResult({ - name: 'Gérer des données', - areaName: 'Information et données', - totalSkillsCount: 4, - testedSkillsCount: 2, - validatedSkillsCount: 2, - }), - domainBuilder.buildCompetenceResult({ - name: 'Gérer des données 2', - areaName: 'Information et données', - totalSkillsCount: 3, - testedSkillsCount: 3, - validatedSkillsCount: 3, - }), - ], - }), - ); - badgeRepository.findByCampaignId.withArgs(campaignId).resolves(badges); - badgeAcquisitionRepository.getAcquiredBadgeIds.withArgs({ badgeIds: [1], userId }).resolves(badgeAcquiredIds); - }); - - it('should notify pole emploi and create pole emploi sending accordingly', async function () { - // given - const expectedResponse = { isSuccessful: 'someValue', code: 'someCode' }; - poleEmploiNotifier.notify - .withArgs(userId, expectedResults, { - authenticationMethodRepository, - httpAgent, - logger, - httpErrorsHelper, - }) - .resolves(expectedResponse); - const poleEmploiSending = Symbol('Pole emploi sending'); - sinon - .stub(PoleEmploiSending, 'buildForParticipationShared') - .withArgs({ - campaignParticipationId, - payload: expectedResults.toString(), - isSuccessful: expectedResponse.isSuccessful, - responseCode: expectedResponse.code, - }) - .returns(poleEmploiSending); - - // when - await sendSharedParticipationResultsToPoleEmploi({ - ...dependencies, - campaignParticipationId, - }); - - // then - expect(poleEmploiSendingRepository.create).to.have.been.calledWithExactly({ poleEmploiSending }); - }); - }); - - context('when campaign is of type ASSESSMENT but organization is not Pole Emploi', function () { - beforeEach(function () { - const campaign = domainBuilder.buildCampaign({ - id: campaignId, - type: 'ASSESSMENT', - organization: { id: organizationId }, - }); - campaignParticipationRepository.get.withArgs(campaignParticipationId).resolves( - domainBuilder.buildCampaignParticipation({ - id: campaignParticipationId, - campaign, - userId, - sharedAt: new Date('2020-01-03'), - createdAt: new Date('2020-01-02'), - }), - ); - campaignRepository.get.withArgs(campaignId).resolves(campaign); - organizationRepository.get.withArgs(organizationId).resolves({ isPoleEmploi: false }); - }); - - it('should not notify to Pole Emploi', async function () { - // when - await sendSharedParticipationResultsToPoleEmploi({ - ...dependencies, - campaignParticipationId, - }); - - // then - sinon.assert.notCalled(poleEmploiNotifier.notify); - }); - }); - - context('when organization is Pole Emploi but campaign is of type PROFILES_COLLECTION', function () { - beforeEach(function () { - const campaign = domainBuilder.buildCampaign({ id: campaignId, campaignId, type: 'PROFILES_COLLECTION' }); - campaignParticipationRepository.get.withArgs(campaignParticipationId).resolves( - domainBuilder.buildCampaignParticipation({ - id: campaignParticipationId, - campaign, - userId, - sharedAt: new Date('2020-01-03'), - createdAt: new Date('2020-01-02'), - }), - ); - campaignRepository.get.withArgs(campaignId).resolves(campaign); - organizationRepository.get - .withArgs(organizationId) - .resolves({ isPoleEmploi: true, organization: { id: organizationId } }); - }); - - it('should not notify to Pole Emploi', async function () { - // when - await sendSharedParticipationResultsToPoleEmploi({ - ...dependencies, - campaignParticipationId, - }); - - // then - sinon.assert.notCalled(poleEmploiNotifier.notify); - }); - }); -}); From dc8beeb5fb45d6e69f331c62373cd21e34ac43bb Mon Sep 17 00:00:00 2001 From: alicegoarnisson Date: Fri, 13 Dec 2024 16:18:09 +0100 Subject: [PATCH 2/5] feat(orga): modified imports in participation shared job --- .../application/jobs/participation-shared-job-controller.js | 2 +- .../jobs/participation-shared-job-controller_test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/prescription/campaign-participation/application/jobs/participation-shared-job-controller.js b/api/src/prescription/campaign-participation/application/jobs/participation-shared-job-controller.js index 97fbc985801..38910d18546 100644 --- a/api/src/prescription/campaign-participation/application/jobs/participation-shared-job-controller.js +++ b/api/src/prescription/campaign-participation/application/jobs/participation-shared-job-controller.js @@ -1,6 +1,6 @@ -import { usecases } from '../../../../../lib/domain/usecases/index.js'; import { JobController } from '../../../../shared/application/jobs/job-controller.js'; import { ParticipationSharedJob } from '../../domain/models/ParticipationSharedJob.js'; +import { usecases } from '../../domain/usecases/index.js'; export class ParticipationSharedJobController extends JobController { constructor() { diff --git a/api/tests/prescription/campaign-participation/unit/application/jobs/participation-shared-job-controller_test.js b/api/tests/prescription/campaign-participation/unit/application/jobs/participation-shared-job-controller_test.js index 1dfd19d4fb3..2f4ad7bd721 100644 --- a/api/tests/prescription/campaign-participation/unit/application/jobs/participation-shared-job-controller_test.js +++ b/api/tests/prescription/campaign-participation/unit/application/jobs/participation-shared-job-controller_test.js @@ -1,5 +1,5 @@ -import { usecases } from '../../../../../../lib/domain/usecases/index.js'; import { ParticipationSharedJobController } from '../../../../../../src/prescription/campaign-participation/application/jobs/participation-shared-job-controller.js'; +import { usecases } from '../../../../../../src/prescription/campaign-participation/domain/usecases/index.js'; import { expect, sinon } from '../../../../../test-helper.js'; describe('Unit | Prescription | Application | Jobs | participationSharedJobController', function () { From 841cc02313b0b3fef34e1abcad779dc6063e981b Mon Sep 17 00:00:00 2001 From: alicegoarnisson Date: Fri, 13 Dec 2024 16:18:38 +0100 Subject: [PATCH 3/5] feat(orga): added necessary dependency to shared results usecase in prescription context --- .../campaign-participation/domain/usecases/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/src/prescription/campaign-participation/domain/usecases/index.js b/api/src/prescription/campaign-participation/domain/usecases/index.js index d7290905314..bf522dbdd49 100644 --- a/api/src/prescription/campaign-participation/domain/usecases/index.js +++ b/api/src/prescription/campaign-participation/domain/usecases/index.js @@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url'; import * as badgeAcquisitionRepository from '../../../../../lib/infrastructure/repositories/badge-acquisition-repository.js'; import * as badgeForCalculationRepository from '../../../../../lib/infrastructure/repositories/badge-for-calculation-repository.js'; +import { campaignParticipationResultRepository } from '../../../../../lib/infrastructure/repositories/campaign-participation-result-repository.js'; import * as campaignRepository from '../../../../../lib/infrastructure/repositories/campaign-repository.js'; import * as knowledgeElementRepository from '../../../../../lib/infrastructure/repositories/knowledge-element-repository.js'; import * as learningContentRepository from '../../../../../lib/infrastructure/repositories/learning-content-repository.js'; @@ -96,6 +97,7 @@ const dependencies = { campaignParticipantRepository: campaignRepositories.campaignParticipantRepository, campaignParticipationOverviewRepository, campaignParticipationRepository, + campaignParticipationResultRepository, campaignProfileRepository, campaignRepository, targetProfileRepository, From f6a3d221cf872cbe7869a2bea4d98fb7e626f647 Mon Sep 17 00:00:00 2001 From: alicegoarnisson Date: Mon, 16 Dec 2024 13:57:20 +0100 Subject: [PATCH 4/5] feat(orga): added unit test back --- ...rticipation-results-to-pole-emploi_test.js | 290 ++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 api/tests/prescription/campaign-participation/unit/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js diff --git a/api/tests/prescription/campaign-participation/unit/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js b/api/tests/prescription/campaign-participation/unit/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js new file mode 100644 index 00000000000..286a820a5fa --- /dev/null +++ b/api/tests/prescription/campaign-participation/unit/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js @@ -0,0 +1,290 @@ +import { PoleEmploiSending } from '../../../../../../src/prescription/campaign-participation/domain/models/PoleEmploiSending.js'; +import { sendSharedParticipationResultsToPoleEmploi } from '../../../../../../src/prescription/campaign-participation/domain/usecases/send-shared-participation-results-to-pole-emploi.js'; +import { PoleEmploiPayload } from '../../../../../../src/prescription/campaign-participation/infrastructure/externals/pole-emploi/PoleEmploiPayload.js'; +import { config } from '../../../../../../src/shared/config.js'; +import { domainBuilder, expect, sinon } from '../../../../../test-helper.js'; + +describe('Unit | Domain | UseCase | send-shared-participation-results-to-pole-emploi', function () { + let dependencies, expectedResults; + let campaignRepository, + badgeRepository, + badgeAcquisitionRepository, + campaignParticipationRepository, + campaignParticipationResultRepository, + organizationRepository, + targetProfileRepository, + userRepository, + poleEmploiNotifier, + poleEmploiSendingRepository; + let httpAgent, httpErrorsHelper, logger; + let campaignId, campaignParticipationId, userId, organizationId, badges, badgeAcquiredIds; + let authenticationMethodRepository; + + beforeEach(function () { + httpAgent = Symbol('httpAgent'); + logger = Symbol('logger'); + httpErrorsHelper = Symbol('httpErrorsHelper'); + badgeRepository = { findByCampaignId: sinon.stub() }; + badgeAcquisitionRepository = { getAcquiredBadgeIds: sinon.stub() }; + campaignRepository = { get: sinon.stub() }; + campaignParticipationRepository = { get: sinon.stub() }; + campaignParticipationResultRepository = { getByParticipationId: sinon.stub() }; + organizationRepository = { get: sinon.stub() }; + targetProfileRepository = { get: sinon.stub() }; + userRepository = { get: sinon.stub() }; + poleEmploiNotifier = { notify: sinon.stub() }; + poleEmploiSendingRepository = { create: sinon.stub() }; + authenticationMethodRepository = { + findOneByUserIdAndIdentityProvider: sinon.stub(), + updateAuthenticationComplementByUserIdAndIdentityProvider: sinon.stub(), + }; + + dependencies = { + authenticationMethodRepository, + badgeRepository, + badgeAcquisitionRepository, + campaignRepository, + campaignParticipationRepository, + campaignParticipationResultRepository, + organizationRepository, + poleEmploiSendingRepository, + targetProfileRepository, + userRepository, + poleEmploiNotifier, + notifierDependencies: { + httpAgent, + logger, + httpErrorsHelper, + }, + }; + + expectedResults = new PoleEmploiPayload({ + campagne: { + nom: 'Campagne Pôle Emploi', + dateDebut: new Date('2020-01-01'), + dateFin: new Date('2020-02-01'), + type: 'EVALUATION', + codeCampagne: 'CODEPE123', + urlCampagne: `${config.domain.pixApp + config.domain.tldFr}/campagnes/CODEPE123`, + nomOrganisme: 'Pix', + typeOrganisme: 'externe', + }, + individu: { + nom: 'Bonneau', + prenom: 'Jean', + }, + test: { + etat: 4, + progression: 100, + typeTest: 'DI', + referenceExterne: 55667788, + dateDebut: new Date('2020-01-02'), + dateProgression: new Date('2020-01-03'), + dateValidation: new Date('2020-01-03'), + evaluation: 70, + uniteEvaluation: 'A', + elementsEvalues: [ + { + libelle: 'Gérer des données', + categorie: 'competence', + type: 'competence Pix', + domaineRattachement: 'Information et données', + nbSousElements: 4, + evaluation: { + scoreObtenu: 50, + uniteScore: 'A', + nbSousElementValide: 2, + }, + }, + { + libelle: 'Gérer des données 2', + categorie: 'competence', + type: 'competence Pix', + domaineRattachement: 'Information et données', + nbSousElements: 3, + evaluation: { + scoreObtenu: 100, + uniteScore: 'A', + nbSousElementValide: 3, + }, + }, + ], + }, + badges: [ + { + cle: 1, + titre: 'titre', + message: 'message', + imageUrl: 'imageUrl', + messageAlternatif: 'messageAlternatif', + certifiable: true, + obtenu: true, + }, + ], + }); + badges = [ + { + id: 1, + key: 1, + title: 'titre', + message: 'message', + imageUrl: 'imageUrl', + altMessage: 'messageAlternatif', + isCertifiable: true, + }, + ]; + badgeAcquiredIds = [1]; + campaignId = Symbol('campaignId'); + campaignParticipationId = 55667788; + userId = Symbol('userId'); + organizationId = Symbol('organizationId'); + }); + + context('when campaign is of type ASSESSMENT and organization is Pole Emploi', function () { + beforeEach(function () { + organizationRepository.get.withArgs(organizationId).resolves({ isPoleEmploi: true }); + userRepository.get + .withArgs(userId) + .resolves(domainBuilder.buildUser({ id: userId, firstName: 'Jean', lastName: 'Bonneau' })); + targetProfileRepository.get.withArgs('targetProfileId1').resolves({ name: 'Diagnostic initial' }); + const campaign = domainBuilder.buildCampaign({ + id: campaignId, + name: 'Campagne Pôle Emploi', + code: 'CODEPE123', + createdAt: new Date('2020-01-01'), + archivedAt: new Date('2020-02-01'), + type: 'ASSESSMENT', + targetProfile: { id: 'targetProfileId1' }, + organization: { id: organizationId }, + }); + campaignParticipationRepository.get.withArgs(campaignParticipationId).resolves( + domainBuilder.buildCampaignParticipation({ + id: campaignParticipationId, + campaign, + userId, + sharedAt: new Date('2020-01-03'), + createdAt: new Date('2020-01-02'), + }), + ); + campaignRepository.get.withArgs(campaignId).resolves(campaign); + campaignParticipationResultRepository.getByParticipationId.withArgs(campaignParticipationId).resolves( + domainBuilder.buildCampaignParticipationResult({ + totalSkillsCount: 10, + validatedSkillsCount: 7, + competenceResults: [ + domainBuilder.buildCompetenceResult({ + name: 'Gérer des données', + areaName: 'Information et données', + totalSkillsCount: 4, + testedSkillsCount: 2, + validatedSkillsCount: 2, + }), + domainBuilder.buildCompetenceResult({ + name: 'Gérer des données 2', + areaName: 'Information et données', + totalSkillsCount: 3, + testedSkillsCount: 3, + validatedSkillsCount: 3, + }), + ], + }), + ); + badgeRepository.findByCampaignId.withArgs(campaignId).resolves(badges); + badgeAcquisitionRepository.getAcquiredBadgeIds.withArgs({ badgeIds: [1], userId }).resolves(badgeAcquiredIds); + }); + + it('should notify pole emploi and create pole emploi sending accordingly', async function () { + // given + const expectedResponse = { isSuccessful: 'someValue', code: 'someCode' }; + poleEmploiNotifier.notify + .withArgs(userId, expectedResults, { + authenticationMethodRepository, + httpAgent, + logger, + httpErrorsHelper, + }) + .resolves(expectedResponse); + const poleEmploiSending = Symbol('Pole emploi sending'); + sinon + .stub(PoleEmploiSending, 'buildForParticipationShared') + .withArgs({ + campaignParticipationId, + payload: expectedResults.toString(), + isSuccessful: expectedResponse.isSuccessful, + responseCode: expectedResponse.code, + }) + .returns(poleEmploiSending); + + // when + await sendSharedParticipationResultsToPoleEmploi({ + ...dependencies, + campaignParticipationId, + }); + + // then + expect(poleEmploiSendingRepository.create).to.have.been.calledWithExactly({ poleEmploiSending }); + }); + }); + + context('when campaign is of type ASSESSMENT but organization is not Pole Emploi', function () { + beforeEach(function () { + const campaign = domainBuilder.buildCampaign({ + id: campaignId, + type: 'ASSESSMENT', + organization: { id: organizationId }, + }); + campaignParticipationRepository.get.withArgs(campaignParticipationId).resolves( + domainBuilder.buildCampaignParticipation({ + id: campaignParticipationId, + campaign, + userId, + sharedAt: new Date('2020-01-03'), + createdAt: new Date('2020-01-02'), + }), + ); + campaignRepository.get.withArgs(campaignId).resolves(campaign); + organizationRepository.get.withArgs(organizationId).resolves({ isPoleEmploi: false }); + }); + + it('should not notify to Pole Emploi', async function () { + // when + await sendSharedParticipationResultsToPoleEmploi({ + ...dependencies, + campaignParticipationId, + }); + + // then + sinon.assert.notCalled(poleEmploiNotifier.notify); + }); + }); + + context('when organization is Pole Emploi but campaign is of type PROFILES_COLLECTION', function () { + beforeEach(function () { + const campaign = domainBuilder.buildCampaign({ id: campaignId, campaignId, type: 'PROFILES_COLLECTION' }); + campaignParticipationRepository.get.withArgs(campaignParticipationId).resolves( + domainBuilder.buildCampaignParticipation({ + id: campaignParticipationId, + campaign, + userId, + sharedAt: new Date('2020-01-03'), + createdAt: new Date('2020-01-02'), + }), + ); + campaignRepository.get.withArgs(campaignId).resolves(campaign); + organizationRepository.get + .withArgs(organizationId) + .resolves({ isPoleEmploi: true, organization: { id: organizationId } }); + }); + + it('should not notify to Pole Emploi', async function () { + // when + await sendSharedParticipationResultsToPoleEmploi({ + ...dependencies, + campaignParticipationId, + }); + + // then + sinon.assert.notCalled(poleEmploiNotifier.notify); + }); + }); +}); From 3871eb6a64318f24926b557258f1ef1042556121 Mon Sep 17 00:00:00 2001 From: alicegoarnisson Date: Mon, 16 Dec 2024 14:44:04 +0100 Subject: [PATCH 5/5] feat(orga): moving campaign participation result repository --- api/lib/domain/events/index.js | 2 -- api/lib/domain/usecases/index.js | 2 -- ...insert-missing-pole-emploi-sending-from-date.js | 2 +- .../domain/usecases/index.js | 2 +- .../campaign-participation-result-repository.js | 14 +++++++------- ...ampaign-participation-result-repository_test.js | 8 ++++---- 6 files changed, 13 insertions(+), 17 deletions(-) rename api/{lib => src/prescription/campaign-participation}/infrastructure/repositories/campaign-participation-result-repository.js (55%) rename api/tests/{ => prescription/campaign-participation}/integration/infrastructure/repositories/campaign-participation-result-repository_test.js (96%) diff --git a/api/lib/domain/events/index.js b/api/lib/domain/events/index.js index 78faecb4427..44ace1bb343 100644 --- a/api/lib/domain/events/index.js +++ b/api/lib/domain/events/index.js @@ -35,7 +35,6 @@ import * as eventBusBuilder from '../../infrastructure/events/EventBusBuilder.js import { EventDispatcher } from '../../infrastructure/events/EventDispatcher.js'; import { EventDispatcherLogger } from '../../infrastructure/events/EventDispatcherLogger.js'; import * as badgeAcquisitionRepository from '../../infrastructure/repositories/badge-acquisition-repository.js'; -import * as campaignParticipationResultRepository from '../../infrastructure/repositories/campaign-participation-result-repository.js'; import * as campaignRepository from '../../infrastructure/repositories/campaign-repository.js'; import * as complementaryCertificationCourseResultRepository from '../../infrastructure/repositories/complementary-certification-course-result-repository.js'; import * as complementaryCertificationScoringCriteriaRepository from '../../infrastructure/repositories/complementary-certification-scoring-criteria-repository.js'; @@ -53,7 +52,6 @@ const dependencies = { authenticationMethodRepository, badgeAcquisitionRepository, campaignRepository, - campaignParticipationResultRepository, certificationAssessmentHistoryRepository, certificationAssessmentRepository, certificationCenterRepository, diff --git a/api/lib/domain/usecases/index.js b/api/lib/domain/usecases/index.js index 41f5d85debb..3b06b7e9ed0 100644 --- a/api/lib/domain/usecases/index.js +++ b/api/lib/domain/usecases/index.js @@ -128,7 +128,6 @@ import * as passwordGenerator from '../../domain/services/password-generator.js' import * as verifyCertificateCodeService from '../../domain/services/verify-certificate-code-service.js'; import * as badgeAcquisitionRepository from '../../infrastructure/repositories/badge-acquisition-repository.js'; import * as badgeForCalculationRepository from '../../infrastructure/repositories/badge-for-calculation-repository.js'; -import { campaignParticipationResultRepository } from '../../infrastructure/repositories/campaign-participation-result-repository.js'; import * as campaignRepository from '../../infrastructure/repositories/campaign-repository.js'; import * as certifiableProfileForLearningContentRepository from '../../infrastructure/repositories/certifiable-profile-for-learning-content-repository.js'; import * as complementaryCertificationCourseResultRepository from '../../infrastructure/repositories/complementary-certification-course-result-repository.js'; @@ -212,7 +211,6 @@ const dependencies = { campaignManagementRepository, participationCompletedJobRepository, campaignParticipationRepository, - campaignParticipationResultRepository, campaignProfileRepository, campaignRepository, centerRepository, diff --git a/api/scripts/prod/insert-missing-pole-emploi-sending-from-date.js b/api/scripts/prod/insert-missing-pole-emploi-sending-from-date.js index 9f3e741d040..85ef64a1b95 100644 --- a/api/scripts/prod/insert-missing-pole-emploi-sending-from-date.js +++ b/api/scripts/prod/insert-missing-pole-emploi-sending-from-date.js @@ -4,7 +4,6 @@ import dayjs from 'dayjs'; import { disconnect, knex } from '../../db/knex-database-connection.js'; import * as badgeAcquisitionRepository from '../../lib/infrastructure/repositories/badge-acquisition-repository.js'; -import { campaignParticipationResultRepository } from '../../lib/infrastructure/repositories/campaign-participation-result-repository.js'; import * as campaignRepository from '../../lib/infrastructure/repositories/campaign-repository.js'; import * as targetProfileRepository from '../../lib/infrastructure/repositories/target-profile-repository.js'; import * as badgeRepository from '../../src/evaluation/infrastructure/repositories/badge-repository.js'; @@ -12,6 +11,7 @@ import * as userRepository from '../../src/identity-access-management/infrastruc import { PoleEmploiSending } from '../../src/prescription/campaign-participation/domain/models/PoleEmploiSending.js'; import { PoleEmploiPayload } from '../../src/prescription/campaign-participation/infrastructure/externals/pole-emploi/PoleEmploiPayload.js'; import * as campaignParticipationRepository from '../../src/prescription/campaign-participation/infrastructure/repositories/campaign-participation-repository.js'; +import { campaignParticipationResultRepository } from '../../src/prescription/campaign-participation/infrastructure/repositories/campaign-participation-result-repository.js'; import * as poleEmploiSendingRepository from '../../src/prescription/campaign-participation/infrastructure/repositories/pole-emploi-sending-repository.js'; import { CampaignParticipationStatuses } from '../../src/prescription/shared/domain/constants.js'; import { Assessment } from '../../src/shared/domain/models/Assessment.js'; diff --git a/api/src/prescription/campaign-participation/domain/usecases/index.js b/api/src/prescription/campaign-participation/domain/usecases/index.js index bf522dbdd49..d596c0845dc 100644 --- a/api/src/prescription/campaign-participation/domain/usecases/index.js +++ b/api/src/prescription/campaign-participation/domain/usecases/index.js @@ -3,7 +3,6 @@ import { fileURLToPath } from 'node:url'; import * as badgeAcquisitionRepository from '../../../../../lib/infrastructure/repositories/badge-acquisition-repository.js'; import * as badgeForCalculationRepository from '../../../../../lib/infrastructure/repositories/badge-for-calculation-repository.js'; -import { campaignParticipationResultRepository } from '../../../../../lib/infrastructure/repositories/campaign-participation-result-repository.js'; import * as campaignRepository from '../../../../../lib/infrastructure/repositories/campaign-repository.js'; import * as knowledgeElementRepository from '../../../../../lib/infrastructure/repositories/knowledge-element-repository.js'; import * as learningContentRepository from '../../../../../lib/infrastructure/repositories/learning-content-repository.js'; @@ -32,6 +31,7 @@ import * as campaignAssessmentParticipationRepository from '../../infrastructure import * as campaignAssessmentParticipationResultRepository from '../../infrastructure/repositories/campaign-assessment-participation-result-repository.js'; import * as campaignParticipationOverviewRepository from '../../infrastructure/repositories/campaign-participation-overview-repository.js'; import * as campaignParticipationRepository from '../../infrastructure/repositories/campaign-participation-repository.js'; +import { campaignParticipationResultRepository } from '../../infrastructure/repositories/campaign-participation-result-repository.js'; import * as campaignProfileRepository from '../../infrastructure/repositories/campaign-profile-repository.js'; import { repositories as campaignRepositories } from '../../infrastructure/repositories/index.js'; // needed to includes organizationFeatureAPI from another BC import { participationResultCalculationJobRepository } from '../../infrastructure/repositories/jobs/participation-result-calculation-job-repository.js'; diff --git a/api/lib/infrastructure/repositories/campaign-participation-result-repository.js b/api/src/prescription/campaign-participation/infrastructure/repositories/campaign-participation-result-repository.js similarity index 55% rename from api/lib/infrastructure/repositories/campaign-participation-result-repository.js rename to api/src/prescription/campaign-participation/infrastructure/repositories/campaign-participation-result-repository.js index 3f85b4f400c..195730b062d 100644 --- a/api/lib/infrastructure/repositories/campaign-participation-result-repository.js +++ b/api/src/prescription/campaign-participation/infrastructure/repositories/campaign-participation-result-repository.js @@ -1,10 +1,10 @@ -import { CampaignParticipationResult } from '../../../src/shared/domain/models/CampaignParticipationResult.js'; -import * as areaRepository from '../../../src/shared/infrastructure/repositories/area-repository.js'; -import * as assessmentRepository from '../../../src/shared/infrastructure/repositories/assessment-repository.js'; -import * as competenceRepository from '../../../src/shared/infrastructure/repositories/competence-repository.js'; -import * as campaignParticipationRepository from './../../../src/prescription/campaign-participation/infrastructure/repositories/campaign-participation-repository.js'; -import * as campaignRepository from './campaign-repository.js'; -import * as knowledgeElementRepository from './knowledge-element-repository.js'; +import * as campaignRepository from '../../../../../lib/infrastructure/repositories/campaign-repository.js'; +import * as knowledgeElementRepository from '../../../../../lib/infrastructure/repositories/knowledge-element-repository.js'; +import { CampaignParticipationResult } from '../../../../shared/domain/models/CampaignParticipationResult.js'; +import * as areaRepository from '../../../../shared/infrastructure/repositories/area-repository.js'; +import * as assessmentRepository from '../../../../shared/infrastructure/repositories/assessment-repository.js'; +import * as competenceRepository from '../../../../shared/infrastructure/repositories/competence-repository.js'; +import * as campaignParticipationRepository from './campaign-participation-repository.js'; const campaignParticipationResultRepository = { async getByParticipationId(campaignParticipationId) { diff --git a/api/tests/integration/infrastructure/repositories/campaign-participation-result-repository_test.js b/api/tests/prescription/campaign-participation/integration/infrastructure/repositories/campaign-participation-result-repository_test.js similarity index 96% rename from api/tests/integration/infrastructure/repositories/campaign-participation-result-repository_test.js rename to api/tests/prescription/campaign-participation/integration/infrastructure/repositories/campaign-participation-result-repository_test.js index 8fb8c4e4187..8698c02ef24 100644 --- a/api/tests/integration/infrastructure/repositories/campaign-participation-result-repository_test.js +++ b/api/tests/prescription/campaign-participation/integration/infrastructure/repositories/campaign-participation-result-repository_test.js @@ -1,7 +1,7 @@ -import { campaignParticipationResultRepository } from '../../../../lib/infrastructure/repositories/campaign-participation-result-repository.js'; -import { CampaignParticipationStatuses } from '../../../../src/prescription/shared/domain/constants.js'; -import { KnowledgeElement } from '../../../../src/shared/domain/models/KnowledgeElement.js'; -import { databaseBuilder, expect } from '../../../test-helper.js'; +import { campaignParticipationResultRepository } from '../../../../../../src/prescription/campaign-participation/infrastructure/repositories/campaign-participation-result-repository.js'; +import { CampaignParticipationStatuses } from '../../../../../../src/prescription/shared/domain/constants.js'; +import { KnowledgeElement } from '../../../../../../src/shared/domain/models/KnowledgeElement.js'; +import { databaseBuilder, expect } from '../../../../../test-helper.js'; const { STARTED } = CampaignParticipationStatuses;