Skip to content

Commit

Permalink
see you tomorrow not sure of that
Browse files Browse the repository at this point in the history
  • Loading branch information
xav-car committed Feb 5, 2025
1 parent 698c36c commit 5919150
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions api/src/quest/domain/models/Quest.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class Quest {
* @param {Eligibility} eligibility
*/
isEligible(eligibility) {
if (this.eligibilityRequirements.length === 0) return false;

return this.eligibilityRequirements.every((eligibilityRequirement) =>
this.#checkRequirement(eligibilityRequirement, eligibility),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as campaignParticipationRepository from '../../../prescription/campaign-participation/infrastructure/repositories/campaign-participation-repository.js';
import * as dirtyImportcampaignParticipationRepository from '../../../prescription/campaign-participation/infrastructure/repositories/campaign-participation-repository.js';

export const getQuestResultsForCampaignParticipation = async ({
userId,
campaignParticipationId,
campaignParticipationRepository = dirtyImportcampaignParticipationRepository,
questRepository,
eligibilityRepository,
rewardRepository,
Expand All @@ -16,6 +17,7 @@ export const getQuestResultsForCampaignParticipation = async ({
const campaignParticipation = await campaignParticipationRepository.get(campaignParticipationId);

const eligibilities = await eligibilityRepository.find({ userId });

const eligibility = eligibilities.find(
(eligibility) => eligibility.organizationLearner.id === campaignParticipation.organizationLearnerId,
);
Expand Down
2 changes: 2 additions & 0 deletions api/tests/quest/unit/domain/models/Quest_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { expect } from '../../../../test-helper.js';

describe('Quest | Unit | Domain | Models | Quest ', function () {
describe('#isEligible', function () {
//TODO: add egde case quest without eligibilityRequirement to return false ?

describe('when comparison is "all"', function () {
describe('when data to test is a simple value', function () {
let quest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Quest | Unit | Domain | Usecases | getQuestResultsForCampaignParticipa
campaignParticipationId = 2;
questRepository = { findAll: sinon.stub() };
eligibilityRepository = { find: sinon.stub() };
campaignParticipationRepository = { getCampaignByParticipationId: sinon.stub() };
campaignParticipationRepository = { get: sinon.stub() };
rewardRepository = { getByQuestAndUserId: sinon.stub() };
});

Expand Down Expand Up @@ -47,8 +47,13 @@ describe('Quest | Unit | Domain | Usecases | getQuestResultsForCampaignParticipa
}),
]);

campaignParticipationRepository.get
.withArgs(campaignParticipationId)
.resolves({ organizationLearnerId: 10, targetProfileId: 50 });

eligibilityRepository.find.withArgs({ userId }).resolves([
new Eligibility({
organizationLearner: { id: 10 },
campaignParticipations: [{ id: wrongCampaignParticipationId, targetProfileId: 40 }],
}),
]);
Expand Down Expand Up @@ -81,12 +86,13 @@ describe('Quest | Unit | Domain | Usecases | getQuestResultsForCampaignParticipa
rewardId: 20,
}),
]);
campaignParticipationRepository.getCampaignByParticipationId
.withArgs({ campaignParticipationId })
.resolves([{ targetProfileId: 40 }]);
campaignParticipationRepository.get
.withArgs(campaignParticipationId)
.resolves({ organizationLearnerId: 10, targetProfileId: 40 });

eligibilityRepository.find.withArgs({ userId }).resolves([
new Eligibility({
organizationLearner: { id: 10 },
campaignParticipations: [{ id: campaignParticipationId, targetProfileId: 40 }],
}),
]);
Expand Down

0 comments on commit 5919150

Please sign in to comment.