Skip to content

Commit

Permalink
tech?(api): replace functions by getters for campaign type in shared/…
Browse files Browse the repository at this point in the history
…models/Campaign

Co-authored-by: Yvonnick Frin <[email protected]>
Co-authored-by: Xavier Carron <[email protected]>
  • Loading branch information
3 people committed Mar 6, 2025
1 parent b2013e0 commit 605e1c9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const startWritingCampaignProfilesCollectionResultsToStream = async function ({
let additionalHeaders = [];

//TODO: rewrite when we have only one model for Campaign, for now tests are based on Campaign.js from api context
if (!campaign.isProfilesCollection()) {
if (!campaign.isProfilesCollection) {
throw new CampaignTypeError();
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/shared/domain/models/Assessment.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Assessment {
this.showProgressBar = false;
this.hasCheckpoints = false;
this.showLevelup = false;
if (!this.isFlash() && (campaign.isAssessment() || campaign.isExam())) {
if (!this.isFlash() && (campaign.isAssessment || campaign.isExam)) {
this.showProgressBar = true;
this.hasCheckpoints = true;
this.showLevelup = true;
Expand Down
6 changes: 3 additions & 3 deletions api/src/shared/domain/models/Campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class Campaign {
return _.get(this, 'targetProfile.id', null);
}

isAssessment() {
get isAssessment() {
return this.type === CampaignTypes.ASSESSMENT;
}

isExam() {
get isExam() {
return this.type === CampaignTypes.EXAM;
}

isProfilesCollection() {
get isProfilesCollection() {
return this.type === CampaignTypes.PROFILES_COLLECTION;
}

Expand Down
12 changes: 6 additions & 6 deletions api/tests/unit/domain/models/Campaign_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ describe('Unit | Domain | Models | Campaign', function () {
const campaign = domainBuilder.buildCampaign({ type: CampaignTypes.EXAM });

// when / then
expect(campaign.isExam()).to.be.true;
expect(campaign.isExam).to.be.true;
});

it('should return false when campaign is not of type exam', function () {
// given
const campaign = domainBuilder.buildCampaign.ofTypeProfilesCollection();

// when / then
expect(campaign.isExam()).to.be.false;
expect(campaign.isExam).to.be.false;
});
});

Expand All @@ -74,15 +74,15 @@ describe('Unit | Domain | Models | Campaign', function () {
const campaign = domainBuilder.buildCampaign.ofTypeAssessment();

// when / then
expect(campaign.isAssessment()).to.be.true;
expect(campaign.isAssessment).to.be.true;
});

it('should return false when campaign is not of type assessment', function () {
// given
const campaign = domainBuilder.buildCampaign.ofTypeProfilesCollection();

// when / then
expect(campaign.isAssessment()).to.be.false;
expect(campaign.isAssessment).to.be.false;
});
});

Expand All @@ -93,7 +93,7 @@ describe('Unit | Domain | Models | Campaign', function () {

// when / then
//TODO: rewrite when we have only one Campaign model on domainBuilder
expect(campaign.isProfilesCollection()).to.be.true;
expect(campaign.isProfilesCollection).to.be.true;
});

it('should return false when campaign is not of type profiles collection', function () {
Expand All @@ -102,7 +102,7 @@ describe('Unit | Domain | Models | Campaign', function () {

// when / then
//TODO: rewrite when we have only one Campaign model on domainBuilder
expect(campaign.isProfilesCollection()).to.be.false;
expect(campaign.isProfilesCollection).to.be.false;
});
});

Expand Down

0 comments on commit 605e1c9

Please sign in to comment.