Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Ne pas afficher le bloc des attestations si un utilisateur est anonyme (PIX-17118) #11770

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default class EvaluationResultsHero extends Component {
}

get displayQuestResult() {
return this.featureToggles.featureToggles?.isQuestEnabled && this.hasQuestResults;
return (
this.featureToggles.featureToggles?.isQuestEnabled && !this.currentUser.user.isAnonymous && this.hasQuestResults
);
}

get hasQuestResults() {
Expand Down
10 changes: 7 additions & 3 deletions mon-pix/app/routes/campaigns/assessment/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ export default class ResultsRoute extends Route {
}

async model() {
let questResults = [];
const user = this.currentUser.user;
const { campaignParticipation, campaign } = this.modelFor('campaigns.assessment');

try {
const campaignParticipationResult = await this.store.queryRecord('campaign-participation-result', {
campaignId: campaign.id,
userId: user.id,
});

const questResults = await this.store.query('quest-result', {
campaignParticipationId: campaignParticipationResult.id,
});
if (!user.isAnonymous) {
questResults = await this.store.query('quest-result', {
campaignParticipationId: campaignParticipationResult.id,
});
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,87 +51,144 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation

module('display quests results', function () {
module('isQuestEnabled feature flag', function () {
test('it should not display the quest result if the flag is false', async function (assert) {
// given
class FeatureTogglesStub extends Service {
featureToggles = { isQuestEnabled: false };
}
this.owner.register('service:featureToggles', FeatureTogglesStub);
module('user is Anonymous', function () {
test('it should not display the quest result if the flag is false', async function (assert) {
// given
class CurrentUserStub extends Service {
user = { isAnonymous: true };
}
this.owner.register('service:currentUser', CurrentUserStub);
class FeatureTogglesStub extends Service {
featureToggles = { isQuestEnabled: false };
}
this.owner.register('service:featureToggles', FeatureTogglesStub);

this.set('campaign', {
customResultPageText: 'My custom result page text',
organizationId: 1,
});
this.set('campaign', {
customResultPageText: 'My custom result page text',
organizationId: 1,
});

this.set('campaignParticipationResult', {
campaignParticipationBadges: [],
isShared: false,
canImprove: false,
masteryRate: 0.75,
reachedStage: { acquired: 4, total: 5 },
});
this.set('campaignParticipationResult', {
campaignParticipationBadges: [],
isShared: false,
canImprove: false,
masteryRate: 0.75,
reachedStage: { acquired: 4, total: 5 },
});

this.set('questResults', [
{
obtained: true,
profileRewardId: 12,
reward: { key: 'SIXTH_GRADE' },
},
]);
this.set('questResults', [
{
obtained: true,
profileRewardId: 12,
reward: { key: 'SIXTH_GRADE' },
},
]);

// when
const screen = await render(
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
// when
const screen = await render(
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@questResults={{this.questResults}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);
);

// then
assert.notOk(screen.queryByText(t('components.campaigns.attestation-result.obtained')));
// then
assert.notOk(screen.queryByText(t('components.campaigns.attestation-result.obtained')));
});
});

test('it should display the quest result if the flag is true', async function (assert) {
// given
class FeatureTogglesStub extends Service {
featureToggles = { isQuestEnabled: true };
}
this.owner.register('service:featureToggles', FeatureTogglesStub);
module('user is not anonymous', function (hooks) {
hooks.beforeEach(function () {
class CurrentUserStub extends Service {
user = { isAnonymous: false };
}
this.owner.register('service:currentUser', CurrentUserStub);

this.set('campaign', {
customResultPageText: 'My custom result page text',
organizationId: 1,
});
test('it should not display the quest result if the flag is true', async function (assert) {
// given
class FeatureTogglesStub extends Service {
featureToggles = { isQuestEnabled: true };
}
this.owner.register('service:featureToggles', FeatureTogglesStub);

this.set('campaignParticipationResult', {
campaignParticipationBadges: [],
isShared: false,
canImprove: false,
masteryRate: 0.75,
reachedStage: { acquired: 4, total: 5 },
});
this.set('questResults', [
{
obtained: true,
profileRewardId: 12,
reward: { key: 'SIXTH_GRADE' },
},
]);
this.set('campaign', {
customResultPageText: 'My custom result page text',
organizationId: 1,
});

// when
const screen = await render(
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
this.set('campaignParticipationResult', {
campaignParticipationBadges: [],
isShared: false,
canImprove: false,
masteryRate: 0.75,
reachedStage: { acquired: 4, total: 5 },
});

this.set('questResults', [
{
obtained: true,
profileRewardId: 12,
reward: { key: 'SIXTH_GRADE' },
},
]);

// when
const screen = await render(
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@questResults={{this.questResults}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);
);

// then
assert.ok(screen.getByText(t('components.campaigns.attestation-result.obtained')));
// then
assert.notOk(screen.queryByText(t('components.campaigns.attestation-result.obtained')));
});

test('it should display the quest result if the flag is true', async function (assert) {
// given
class FeatureTogglesStub extends Service {
featureToggles = { isQuestEnabled: true };
}
this.owner.register('service:featureToggles', FeatureTogglesStub);

this.set('campaign', {
customResultPageText: 'My custom result page text',
organizationId: 1,
});

this.set('campaignParticipationResult', {
campaignParticipationBadges: [],
isShared: false,
canImprove: false,
masteryRate: 0.75,
reachedStage: { acquired: 4, total: 5 },
});
this.set('questResults', [
{
obtained: true,
profileRewardId: 12,
reward: { key: 'SIXTH_GRADE' },
},
]);

// when
const screen = await render(
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@questResults={{this.questResults}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);

// then
assert.ok(screen.getByText(t('components.campaigns.attestation-result.obtained')));
});
});
});
});
});
Expand Down
118 changes: 118 additions & 0 deletions mon-pix/tests/unit/routes/campaigns/assessment/results-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import Service from '@ember/service';
import { setupTest } from 'ember-qunit';
import { module, test } from 'qunit';
import sinon from 'sinon';

module('Unit | Route | Campaign | Assessment | Results', function (hooks) {
setupTest(hooks);

let route, modelForStub, transitionToStub, queryRecordStub, queryStub;
const campaign = { id: '123456', code: 'NEW_CODE' };
const questResults = [{ obtained: true, reward: { key: 'reward-key' } }];
const campaignParticipation = { id: '1212', isShared: true, hasMany: sinon.stub() };
const campaignParticipationResult = { id: campaignParticipation.id, campaignId: campaign.id };

hooks.beforeEach(function () {
route = this.owner.lookup('route:campaigns.assessment.results');
const store = this.owner.lookup('service:store');

modelForStub = sinon.stub(route, 'modelFor');
transitionToStub = sinon.stub(route.router, 'transitionTo');
modelForStub.returns({ campaign, campaignParticipation });
queryRecordStub = sinon.stub(store, 'queryRecord');
queryStub = sinon.stub(store, 'query');

campaignParticipation.hasMany.returns({ reload: sinon.stub() });
});

module('#model', function () {
module('when no participation', function () {
test('should redirect to start or resume', async function (assert) {
class CurrentUserStub extends Service {
user = {
id: '1234',
};
}
this.owner.register('service:current-user', CurrentUserStub);

queryRecordStub
.withArgs('campaign-participation-result', { campaignId: campaign.id, userId: '1234' })
.rejects({ errors: [{ status: '412' }] });

await route.model();
sinon.assert.calledWith(transitionToStub, 'campaigns.entry-point', 'NEW_CODE');
assert.ok(true);
});
});

module('when participation exists', function () {
test('should call quest result on connected user', async function (assert) {
class CurrentUserStub extends Service {
user = {
id: '1234',
isAnonymous: false,
};
}
this.owner.register('service:current-user', CurrentUserStub);

queryRecordStub
.withArgs('campaign-participation-result', { campaignId: campaign.id, userId: '1234' })
.resolves(campaignParticipationResult);
queryStub
.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id })
.resolves(questResults);

await route.model();

assert.true(
queryStub.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id }).called,
);
});

test('should not call quest result on anonymous user', async function (assert) {
class CurrentUserStub extends Service {
user = {
id: '1234',
isAnonymous: true,
};
}
this.owner.register('service:current-user', CurrentUserStub);

queryRecordStub
.withArgs('campaign-participation-result', { campaignId: campaign.id, userId: '1234' })
.resolves(campaignParticipationResult);
queryStub
.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id })
.resolves(questResults);

await route.model();

assert.false(
queryStub.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id }).called,
);
});

test('should not redirect', async function (assert) {
class CurrentUserStub extends Service {
user = {
id: '1234',
isAnonymous: false,
};
}
this.owner.register('service:current-user', CurrentUserStub);

queryRecordStub
.withArgs('campaign-participation-result', { campaignId: campaign.id, userId: '1234' })
.resolves(campaignParticipationResult);
queryStub
.withArgs('quest-result', { campaignParticipationId: campaignParticipationResult.id })
.resolves(questResults);

await route.model();

sinon.assert.notCalled(route.router.transitionTo);
assert.ok(true);
});
});
});
});
Loading