Skip to content

Commit

Permalink
feat(api): canImprove computation takes into account campaign type
Browse files Browse the repository at this point in the history
  • Loading branch information
laura-bergoens authored Mar 7, 2025
1 parent 75262fb commit 96c469d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const getByUserIdAndCampaignId = async function ({ userId, campaignId, badges, r
isOrganizationLearnerActive,
isCampaignArchived,
isCampaignDeleted,
campaignType: campaignDTO.type,
flashScoringResults,
isTargetProfileResetAllowed,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
MINIMUM_DELAY_IN_DAYS_BEFORE_IMPROVING,
MINIMUM_DELAY_IN_DAYS_BEFORE_RETRYING,
} from '../../constants.js';
import { CampaignParticipationStatuses } from '../../models/index.js';
import { CampaignParticipationStatuses, CampaignTypes } from '../../models/index.js';
import { BadgeResult } from './BadgeResult.js';
import { CompetenceResult } from './CompetenceResult.js';

Expand All @@ -18,6 +18,7 @@ class AssessmentResult {
isTargetProfileResetAllowed,
isCampaignArchived,
isCampaignDeleted,
campaignType,
competences,
reachedStage,
badgeResultsDTO,
Expand Down Expand Up @@ -64,7 +65,7 @@ class AssessmentResult {

this.badgeResults = badgeResultsDTO.map((badge) => new BadgeResult(badge, participationResults.acquiredBadgeIds));
this.reachedStage = reachedStage;
this.canImprove = this._computeCanImprove(knowledgeElements, assessmentCreatedAt, this.isShared);
this.canImprove = this._computeCanImprove(knowledgeElements, assessmentCreatedAt, this.isShared, campaignType);
this.isDisabled = this._computeIsDisabled(isCampaignArchived, isCampaignDeleted, participationResults.isDeleted);
this.canRetry = this._computeCanRetry(
isCampaignMultipleSendings,
Expand Down Expand Up @@ -110,7 +111,10 @@ class AssessmentResult {
}
}

_computeCanImprove(knowledgeElements, assessmentCreatedAt, isShared) {
_computeCanImprove(knowledgeElements, assessmentCreatedAt, isShared, campaignType) {
if (campaignType === CampaignTypes.EXAM) {
return false;
}
const isImprovementPossible =
knowledgeElements.filter((knowledgeElement) => {
const isOldEnoughToBeImproved =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { constants } from '../../../../../src/shared/domain/constants.js';
import { CampaignParticipationStatuses, KnowledgeElement } from '../../../../../src/shared/domain/models/index.js';
import {
CampaignParticipationStatuses,
CampaignTypes,
KnowledgeElement,
} from '../../../../../src/shared/domain/models/index.js';
import { AssessmentResult } from '../../../../../src/shared/domain/read-models/participant-results/AssessmentResult.js';
import { domainBuilder, expect, sinon } from '../../../../test-helper.js';

Expand Down Expand Up @@ -914,19 +918,13 @@ describe('Unit | Domain | Read-Models | ParticipantResult | AssessmentResult', f
const assessmentCreatedAt = new Date('2020-01-05T05:06:07Z');
let clock;

before(function () {
sinon.stub(constants, 'MINIMUM_DELAY_IN_DAYS_BEFORE_IMPROVING').value(4);
});

after(function () {
sinon.stub(constants, 'MINIMUM_DELAY_IN_DAYS_BEFORE_IMPROVING').value(originalConstantValue);
});

beforeEach(function () {
sinon.stub(constants, 'MINIMUM_DELAY_IN_DAYS_BEFORE_IMPROVING').value(4);
clock = sinon.useFakeTimers({ now: assessmentCreatedAt, toFake: ['Date'] });
});

afterEach(function () {
sinon.stub(constants, 'MINIMUM_DELAY_IN_DAYS_BEFORE_IMPROVING').value(originalConstantValue);
clock.restore();
});

Expand Down Expand Up @@ -982,6 +980,47 @@ describe('Unit | Domain | Read-Models | ParticipantResult | AssessmentResult', f
});
});

context('by campaign types', function () {
// eslint-disable-next-line mocha/no-setup-in-describe
[
{
// eslint-disable-next-line mocha/no-setup-in-describe
campaignType: CampaignTypes.EXAM,
expected: false,
},
{
// eslint-disable-next-line mocha/no-setup-in-describe
campaignType: CampaignTypes.ASSESSMENT,
expected: true,
},
].forEach(({ campaignType, expected }) => {
it(`returns ${expected} when campaign is of type ${campaignType}`, function () {
const ke = domainBuilder.buildKnowledgeElement({
status: KnowledgeElement.StatusType.INVALIDATED,
createdAt: new Date('2020-01-01'),
});
const participationResults = {
knowledgeElements: [ke],
acquiredBadgeIds: [],
assessmentCreatedAt,
sharedAt: null,
status: CampaignParticipationStatuses.STARTED,
};
const assessmentResult = new AssessmentResult({
participationResults,
competences: [],
stages: [],
badgeResultsDTO: [],
isCampaignMultipleSendings: false,
isOrganizationLearnerActive: false,
campaignType,
});

expect(assessmentResult.canImprove).to.equal(expected);
});
});
});

context('when participation is shared', function () {
it('returns false', function () {
const ke = domainBuilder.buildKnowledgeElement({
Expand Down

0 comments on commit 96c469d

Please sign in to comment.