Skip to content

Commit

Permalink
feat(mon-pix): send translation key when feature toggle is enabled
Browse files Browse the repository at this point in the history
in reset password route model function
  • Loading branch information
er-lim authored Nov 6, 2024
1 parent 61445b7 commit 2964768
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
10 changes: 8 additions & 2 deletions mon-pix/app/routes/reset-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import get from 'lodash/get';

export default class ResetPasswordRoute extends Route {
@service errors;
@service featureToggles;
@service intl;
@service session;
@service router;
@service session;
@service store;

async model(params) {
Expand All @@ -17,7 +18,12 @@ export default class ResetPasswordRoute extends Route {
} catch (error) {
const status = get(error, 'errors[0].status');
if (status && (status === 401 || (status && 404))) {
this.errors.push(this.intl.t('pages.reset-password.error.expired-demand'));
let error = this.intl.t('pages.reset-password.error.expired-demand');

if (this.featureToggles.featureToggles.isNewAuthenticationDesignEnabled) {
error = 'pages.reset-password.error.expired-demand';
}
this.errors.push(error);
this.router.replaceWith('password-reset-demand');
}
}
Expand Down
53 changes: 46 additions & 7 deletions mon-pix/tests/unit/routes/reset-password-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,33 @@ module('Unit | Route | reset-password', function (hooks) {
});
});
module('when password reset demand is not valid', function () {
module('when error status is equal to 401', function () {
test('it adds an error in errors service and replace current route with "reset-password-demand"', async function (assert) {
// given
module('when error status is equal to 401', function (hooks) {
const errorTranslationKey = 'pages.reset-password.error.expired-demand';
let errorsService, replaceWithStub, route, routerStub;

hooks.beforeEach(function () {
const errors = [{ status: 401 }];
const errorsService = this.owner.lookup('service:errors');
const route = this.owner.lookup('route:reset-password');
const replaceWithStub = sinon.stub();
const routerStub = Service.create({
errorsService = this.owner.lookup('service:errors');
route = this.owner.lookup('route:reset-password');
replaceWithStub = sinon.stub();
routerStub = Service.create({
replaceWith: replaceWithStub,
});

queryRecordStub.rejects({ errors });
route.set('store', storeStub);
route.set('router', routerStub);

class FeatureTogglesStub extends Service {
get featureToggles() {
return { isNewAuthenticationDesignEnabled: false };
}
}

this.owner.register('service:feature-toggles', FeatureTogglesStub);
});

test('it replaces current route with "reset-password-demand"', async function (assert) {
// when
await route.model(params);

Expand All @@ -106,6 +118,33 @@ module('Unit | Route | reset-password', function (hooks) {
assert.strictEqual(errorsService.errors.length, 1);
assert.strictEqual(errorsService.errors[0], t('pages.reset-password.error.expired-demand'));
});

test('it adds an error translation key in error service when "New authentication design" feature toggle is enabled', async function (assert) {
// when
await route.model(params);

// then
assert.strictEqual(errorsService.errors.length, 1);
assert.strictEqual(errorsService.errors[0], t(errorTranslationKey));
});

test('it adds an error with its translation in error service when "New authentication design" feature toggle is disabled', async function (assert) {
// given
class FeatureTogglesStub extends Service {
get featureToggles() {
return { isNewAuthenticationDesignEnabled: true };
}
}

this.owner.register('service:feature-toggles', FeatureTogglesStub);

// when
await route.model(params);

// then
assert.strictEqual(errorsService.errors.length, 1);
assert.strictEqual(errorsService.errors[0], errorTranslationKey);
});
});
});
});
Expand Down

0 comments on commit 2964768

Please sign in to comment.