Skip to content

Commit

Permalink
[BUGFIX] Ne pas afficher l'encart attestation pour les participations…
Browse files Browse the repository at this point in the history
… a des campagnes sans lien avec les quêtes (PIX-15308) (#10550)
  • Loading branch information
Alexandre-Monney authored Nov 15, 2024
1 parent 07ef282 commit 059c525
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export const getQuestResultsForCampaignParticipation = async ({

if (!eligibility) return [];

eligibility.campaignParticipations.targetProfileIds = [
// getTargetProfileForCampaignParticipation returns null but this usecase is used for campaign participation result page for now, so the campaign participation ID always exists
// if this usecase is to be used in another context, the edge case must be handled
eligibility.getTargetProfileForCampaignParticipation(campaignParticipationId),
];
/*
This effectively overrides the existing campaignParticipations property with a new getter that always returns the updated targetProfileIds array based on the provided campaignParticipationId.
We can't just reassign the getter with the new value, because the getter will still be called and the new value would be ignored
*/
Object.defineProperty(eligibility, 'campaignParticipations', {
get: () => ({ targetProfileIds: [eligibility.getTargetProfileForCampaignParticipation(campaignParticipationId)] }),
});

const questResults = [];
for (const quest of quests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,55 @@ describe('Quest | Integration | Domain | Usecases | getQuestResultsForCampaignPa
expect(result[0].id).to.equal(questId);
expect(result[0].reward.id).to.equal(rewardId);
});

it('should not return quest results for other campaign participation', async function () {
// given
const organizationId = databaseBuilder.factory.buildOrganization({ type: 'SCO' }).id;
const { id: organizationLearnerId, userId } = databaseBuilder.factory.buildOrganizationLearner({ organizationId });

const { id: notEligibleParticipationId } = databaseBuilder.factory.buildCampaignParticipation({
organizationLearnerId,
userId,
});
const targetProfileId = databaseBuilder.factory.buildTargetProfile({ ownerOrganizationId: organizationId }).id;
const campaignId = databaseBuilder.factory.buildCampaign({ organizationId, targetProfileId }).id;
databaseBuilder.factory.buildCampaignParticipation({
organizationLearnerId,
campaignId,
userId,
});
const rewardId = databaseBuilder.factory.buildAttestation().id;
databaseBuilder.factory.buildQuest({
rewardType: 'attestations',
rewardId,
eligibilityRequirements: [
{
type: 'organization',
data: {
type: 'SCO',
},
comparison: COMPARISON.ALL,
},
{
type: 'campaignParticipations',
data: {
targetProfileIds: [targetProfileId],
},
comparison: COMPARISON.ALL,
},
],
successRequirements: [],
}).id;

await databaseBuilder.commit();

// when
const result = await usecases.getQuestResultsForCampaignParticipation({
userId,
campaignParticipationId: notEligibleParticipationId,
});

// then
expect(result).to.be.empty;
});
});

0 comments on commit 059c525

Please sign in to comment.