-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
841cc02
commit 011150c
Showing
1 changed file
with
290 additions
and
0 deletions.
There are no files selected for viewing
290 changes: 290 additions & 0 deletions
290
...rticipation/unit/domain/usecases/send-shared-participation-results-to-pole-emploi_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
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); | ||
}); | ||
}); | ||
}); |