Skip to content

Commit 05b0ec2

Browse files
committed
feat(mon-pix): hide attestation banner on anonymous user
1 parent 9558a0e commit 05b0ec2

File tree

4 files changed

+169
-77
lines changed

4 files changed

+169
-77
lines changed

mon-pix/app/components/campaigns/assessment/results/evaluation-results-hero/index.gjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export default class EvaluationResultsHero extends Component {
5353
}
5454

5555
get displayQuestResult() {
56-
return this.featureToggles.featureToggles?.isQuestEnabled && this.hasQuestResults;
56+
return (
57+
this.featureToggles.featureToggles?.isQuestEnabled && !this.currentUser.user.isAnonymous && this.hasQuestResults
58+
);
5759
}
5860

5961
get hasQuestResults() {

mon-pix/app/routes/campaigns/assessment/results.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@ export default class ResultsRoute extends Route {
1212
}
1313

1414
async model() {
15+
let questResults = [];
1516
const user = this.currentUser.user;
1617
const { campaignParticipation, campaign } = this.modelFor('campaigns.assessment');
18+
1719
try {
1820
const campaignParticipationResult = await this.store.queryRecord('campaign-participation-result', {
1921
campaignId: campaign.id,
2022
userId: user.id,
2123
});
2224

23-
const questResults = await this.store.query('quest-result', {
24-
campaignParticipationId: campaignParticipationResult.id,
25-
});
25+
if (!user.isAnonymous) {
26+
questResults = await this.store.query('quest-result', {
27+
campaignParticipationId: campaignParticipationResult.id,
28+
});
29+
}
2630

2731
const trainings = await campaignParticipation.hasMany('trainings').reload();
2832

mon-pix/tests/integration/components/campaigns/assessment/results/hero/evaluation-results-hero-test.js

+127-70
Original file line numberDiff line numberDiff line change
@@ -51,87 +51,144 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
5151

5252
module('display quests results', function () {
5353
module('isQuestEnabled feature flag', function () {
54-
test('it should not display the quest result if the flag is false', async function (assert) {
55-
// given
56-
class FeatureTogglesStub extends Service {
57-
featureToggles = { isQuestEnabled: false };
58-
}
59-
this.owner.register('service:featureToggles', FeatureTogglesStub);
54+
module('user is Anonymous', function () {
55+
test('it should not display the quest result if the flag is false', async function (assert) {
56+
// given
57+
class CurrentUserStub extends Service {
58+
user = { isAnonymous: true };
59+
}
60+
this.owner.register('service:currentUser', CurrentUserStub);
61+
class FeatureTogglesStub extends Service {
62+
featureToggles = { isQuestEnabled: false };
63+
}
64+
this.owner.register('service:featureToggles', FeatureTogglesStub);
6065

61-
this.set('campaign', {
62-
customResultPageText: 'My custom result page text',
63-
organizationId: 1,
64-
});
66+
this.set('campaign', {
67+
customResultPageText: 'My custom result page text',
68+
organizationId: 1,
69+
});
6570

66-
this.set('campaignParticipationResult', {
67-
campaignParticipationBadges: [],
68-
isShared: false,
69-
canImprove: false,
70-
masteryRate: 0.75,
71-
reachedStage: { acquired: 4, total: 5 },
72-
});
71+
this.set('campaignParticipationResult', {
72+
campaignParticipationBadges: [],
73+
isShared: false,
74+
canImprove: false,
75+
masteryRate: 0.75,
76+
reachedStage: { acquired: 4, total: 5 },
77+
});
7378

74-
this.set('questResults', [
75-
{
76-
obtained: true,
77-
profileRewardId: 12,
78-
reward: { key: 'SIXTH_GRADE' },
79-
},
80-
]);
79+
this.set('questResults', [
80+
{
81+
obtained: true,
82+
profileRewardId: 12,
83+
reward: { key: 'SIXTH_GRADE' },
84+
},
85+
]);
8186

82-
// when
83-
const screen = await render(
84-
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
85-
@campaign={{this.campaign}}
86-
@questResults={{this.questResults}}
87-
@campaignParticipationResult={{this.campaignParticipationResult}}
88-
@isSharableCampaign={{true}}
89-
/>`,
90-
);
87+
// when
88+
const screen = await render(
89+
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
90+
@campaign={{this.campaign}}
91+
@questResults={{this.questResults}}
92+
@campaignParticipationResult={{this.campaignParticipationResult}}
93+
@isSharableCampaign={{true}}
94+
/>`,
95+
);
9196

92-
// then
93-
assert.notOk(screen.queryByText(t('components.campaigns.attestation-result.obtained')));
97+
// then
98+
assert.notOk(screen.queryByText(t('components.campaigns.attestation-result.obtained')));
99+
});
94100
});
95101

96-
test('it should display the quest result if the flag is true', async function (assert) {
97-
// given
98-
class FeatureTogglesStub extends Service {
99-
featureToggles = { isQuestEnabled: true };
100-
}
101-
this.owner.register('service:featureToggles', FeatureTogglesStub);
102+
module('user is not anonymous', function (hooks) {
103+
hooks.beforeEach(function () {
104+
class CurrentUserStub extends Service {
105+
user = { isAnonymous: false };
106+
}
107+
this.owner.register('service:currentUser', CurrentUserStub);
102108

103-
this.set('campaign', {
104-
customResultPageText: 'My custom result page text',
105-
organizationId: 1,
106-
});
109+
test('it should not display the quest result if the flag is true', async function (assert) {
110+
// given
111+
class FeatureTogglesStub extends Service {
112+
featureToggles = { isQuestEnabled: true };
113+
}
114+
this.owner.register('service:featureToggles', FeatureTogglesStub);
107115

108-
this.set('campaignParticipationResult', {
109-
campaignParticipationBadges: [],
110-
isShared: false,
111-
canImprove: false,
112-
masteryRate: 0.75,
113-
reachedStage: { acquired: 4, total: 5 },
114-
});
115-
this.set('questResults', [
116-
{
117-
obtained: true,
118-
profileRewardId: 12,
119-
reward: { key: 'SIXTH_GRADE' },
120-
},
121-
]);
116+
this.set('campaign', {
117+
customResultPageText: 'My custom result page text',
118+
organizationId: 1,
119+
});
122120

123-
// when
124-
const screen = await render(
125-
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
126-
@campaign={{this.campaign}}
127-
@questResults={{this.questResults}}
128-
@campaignParticipationResult={{this.campaignParticipationResult}}
129-
@isSharableCampaign={{true}}
130-
/>`,
131-
);
121+
this.set('campaignParticipationResult', {
122+
campaignParticipationBadges: [],
123+
isShared: false,
124+
canImprove: false,
125+
masteryRate: 0.75,
126+
reachedStage: { acquired: 4, total: 5 },
127+
});
132128

133-
// then
134-
assert.ok(screen.getByText(t('components.campaigns.attestation-result.obtained')));
129+
this.set('questResults', [
130+
{
131+
obtained: true,
132+
profileRewardId: 12,
133+
reward: { key: 'SIXTH_GRADE' },
134+
},
135+
]);
136+
137+
// when
138+
const screen = await render(
139+
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
140+
@campaign={{this.campaign}}
141+
@questResults={{this.questResults}}
142+
@campaignParticipationResult={{this.campaignParticipationResult}}
143+
@isSharableCampaign={{true}}
144+
/>`,
145+
);
146+
147+
// then
148+
assert.notOk(screen.queryByText(t('components.campaigns.attestation-result.obtained')));
149+
});
150+
151+
test('it should display the quest result if the flag is true', async function (assert) {
152+
// given
153+
class FeatureTogglesStub extends Service {
154+
featureToggles = { isQuestEnabled: true };
155+
}
156+
this.owner.register('service:featureToggles', FeatureTogglesStub);
157+
158+
this.set('campaign', {
159+
customResultPageText: 'My custom result page text',
160+
organizationId: 1,
161+
});
162+
163+
this.set('campaignParticipationResult', {
164+
campaignParticipationBadges: [],
165+
isShared: false,
166+
canImprove: false,
167+
masteryRate: 0.75,
168+
reachedStage: { acquired: 4, total: 5 },
169+
});
170+
this.set('questResults', [
171+
{
172+
obtained: true,
173+
profileRewardId: 12,
174+
reward: { key: 'SIXTH_GRADE' },
175+
},
176+
]);
177+
178+
// when
179+
const screen = await render(
180+
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
181+
@campaign={{this.campaign}}
182+
@questResults={{this.questResults}}
183+
@campaignParticipationResult={{this.campaignParticipationResult}}
184+
@isSharableCampaign={{true}}
185+
/>`,
186+
);
187+
188+
// then
189+
assert.ok(screen.getByText(t('components.campaigns.attestation-result.obtained')));
190+
});
191+
});
135192
});
136193
});
137194
});

mon-pix/tests/unit/routes/campaigns/assessment/results.js mon-pix/tests/unit/routes/campaigns/assessment/results-test.js

+32-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ module('Unit | Route | Campaign | Assessment | Results', function (hooks) {
99
const campaign = { id: '123456', code: 'NEW_CODE' };
1010
const questResults = [{ obtained: true, reward: { key: 'reward-key' } }];
1111
const campaignParticipation = { id: '1212', isShared: true, hasMany: sinon.stub() };
12-
const user = { id: '567890' };
12+
const user = { id: '567890', isAnonymous: false };
1313
const storeStub = {
1414
queryRecord: sinon.stub(),
1515
query: sinon.stub(),
1616
};
17+
const campaignParticipationResult = { id: campaignParticipation.id, campaignId: campaign.id };
1718
const currentUserStub = { user };
1819

1920
hooks.beforeEach(function () {
@@ -42,12 +43,40 @@ module('Unit | Route | Campaign | Assessment | Results', function (hooks) {
4243
hooks.beforeEach(function () {
4344
storeStub.queryRecord
4445
.withArgs('campaign-participation-result', { campaignId: campaign.id, userId: user.id })
45-
.resolves(campaign);
46+
.resolves(campaignParticipationResult);
4647
storeStub.query
47-
.withArgs('quest-result', { campaignParticipationId: campaignParticipation.id })
48+
.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id })
4849
.resolves(questResults);
4950
});
5051

52+
test('should call quest result on connected user', async function (assert) {
53+
const user = { id: '567890', isAnonymous: false };
54+
const currentUserStub = { user };
55+
56+
route.currentUser = currentUserStub;
57+
58+
await route.model();
59+
60+
sinon.assert.called(
61+
storeStub.query.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id }),
62+
);
63+
assert.ok(true);
64+
});
65+
66+
test('should not call quest result on anonymous user', async function (assert) {
67+
const user = { id: '567890', isAnonymous: true };
68+
const currentUserStub = { user };
69+
70+
route.currentUser = currentUserStub;
71+
72+
await route.model();
73+
74+
sinon.assert.notCalled(
75+
storeStub.query.withArgs('quest-result', { campaignParticipationId: campaignParticipation.id }),
76+
);
77+
assert.ok(true);
78+
});
79+
5180
test('should not redirect', async function (assert) {
5281
await route.model();
5382

0 commit comments

Comments
 (0)