Skip to content

Commit d4ada19

Browse files
committed
feat(mon-pix): hide attestation banner on anonymous user
1 parent 57ec20a commit d4ada19

File tree

5 files changed

+245
-123
lines changed

5 files changed

+245
-123
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

+117-60
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
87+
// when
88+
const screen = await render(
89+
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
8590
@campaign={{this.campaign}}
8691
@questResults={{this.questResults}}
8792
@campaignParticipationResult={{this.campaignParticipationResult}}
8893
@isSharableCampaign={{true}}
8994
/>`,
90-
);
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
121+
this.set('campaignParticipationResult', {
122+
campaignParticipationBadges: [],
123+
isShared: false,
124+
canImprove: false,
125+
masteryRate: 0.75,
126+
reachedStage: { acquired: 4, total: 5 },
127+
});
128+
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
126140
@campaign={{this.campaign}}
127141
@questResults={{this.questResults}}
128142
@campaignParticipationResult={{this.campaignParticipationResult}}
129143
@isSharableCampaign={{true}}
130144
/>`,
131-
);
145+
);
132146

133-
// then
134-
assert.ok(screen.getByText(t('components.campaigns.attestation-result.obtained')));
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
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import Service from '@ember/service';
2+
import { setupTest } from 'ember-qunit';
3+
import { module, test } from 'qunit';
4+
import sinon from 'sinon';
5+
6+
module('Unit | Route | Campaign | Assessment | Results', function (hooks) {
7+
setupTest(hooks);
8+
9+
let route, modelForStub, transitionToStub, queryRecordStub, queryStub;
10+
const campaign = { id: '123456', code: 'NEW_CODE' };
11+
const questResults = [{ obtained: true, reward: { key: 'reward-key' } }];
12+
const campaignParticipation = { id: '1212', isShared: true, hasMany: sinon.stub() };
13+
const campaignParticipationResult = { id: campaignParticipation.id, campaignId: campaign.id };
14+
15+
hooks.beforeEach(function () {
16+
route = this.owner.lookup('route:campaigns.assessment.results');
17+
const store = this.owner.lookup('service:store');
18+
19+
modelForStub = sinon.stub(route, 'modelFor');
20+
transitionToStub = sinon.stub(route.router, 'transitionTo');
21+
modelForStub.returns({ campaign, campaignParticipation });
22+
queryRecordStub = sinon.stub(store, 'queryRecord');
23+
queryStub = sinon.stub(store, 'query');
24+
25+
campaignParticipation.hasMany.returns({ reload: sinon.stub() });
26+
});
27+
28+
module('#model', function () {
29+
module('when no participation', function () {
30+
test('should redirect to start or resume', async function (assert) {
31+
class CurrentUserStub extends Service {
32+
user = {
33+
id: '1234',
34+
};
35+
}
36+
this.owner.register('service:current-user', CurrentUserStub);
37+
38+
queryRecordStub
39+
.withArgs('campaign-participation-result', { campaignId: campaign.id, userId: '1234' })
40+
.rejects({ errors: [{ status: '412' }] });
41+
42+
await route.model();
43+
sinon.assert.calledWith(transitionToStub, 'campaigns.entry-point', 'NEW_CODE');
44+
assert.ok(true);
45+
});
46+
});
47+
48+
module('when participation exists', function () {
49+
test('should call quest result on connected user', async function (assert) {
50+
class CurrentUserStub extends Service {
51+
user = {
52+
id: '1234',
53+
isAnonymous: false,
54+
};
55+
}
56+
this.owner.register('service:current-user', CurrentUserStub);
57+
58+
queryRecordStub
59+
.withArgs('campaign-participation-result', { campaignId: campaign.id, userId: '1234' })
60+
.resolves(campaignParticipationResult);
61+
queryStub
62+
.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id })
63+
.resolves(questResults);
64+
65+
await route.model();
66+
67+
assert.true(
68+
queryStub.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id }).called,
69+
);
70+
});
71+
72+
test('should not call quest result on anonymous user', async function (assert) {
73+
class CurrentUserStub extends Service {
74+
user = {
75+
id: '1234',
76+
isAnonymous: true,
77+
};
78+
}
79+
this.owner.register('service:current-user', CurrentUserStub);
80+
81+
queryRecordStub
82+
.withArgs('campaign-participation-result', { campaignId: campaign.id, userId: '1234' })
83+
.resolves(campaignParticipationResult);
84+
queryStub
85+
.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id })
86+
.resolves(questResults);
87+
88+
await route.model();
89+
90+
assert.false(
91+
queryStub.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id }).called,
92+
);
93+
});
94+
95+
test('should not redirect', async function (assert) {
96+
class CurrentUserStub extends Service {
97+
user = {
98+
id: '1234',
99+
isAnonymous: false,
100+
};
101+
}
102+
this.owner.register('service:current-user', CurrentUserStub);
103+
104+
queryRecordStub
105+
.withArgs('campaign-participation-result', { campaignId: campaign.id, userId: '1234' })
106+
.resolves(campaignParticipationResult);
107+
queryStub
108+
.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id })
109+
.resolves(questResults);
110+
111+
await route.model();
112+
113+
sinon.assert.notCalled(route.router.transitionTo);
114+
assert.ok(true);
115+
});
116+
});
117+
});
118+
});

0 commit comments

Comments
 (0)