From 2964768abb6ff656560235ece1aeb1d4fdd64c13 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Mon, 4 Nov 2024 14:31:38 +0100 Subject: [PATCH] feat(mon-pix): send translation key when feature toggle is enabled in reset password route model function --- mon-pix/app/routes/reset-password.js | 10 +++- .../tests/unit/routes/reset-password-test.js | 53 ++++++++++++++++--- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/mon-pix/app/routes/reset-password.js b/mon-pix/app/routes/reset-password.js index 911fc094730..72251676347 100644 --- a/mon-pix/app/routes/reset-password.js +++ b/mon-pix/app/routes/reset-password.js @@ -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) { @@ -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'); } } diff --git a/mon-pix/tests/unit/routes/reset-password-test.js b/mon-pix/tests/unit/routes/reset-password-test.js index 7f288010bf0..5f775fc3a5d 100644 --- a/mon-pix/tests/unit/routes/reset-password-test.js +++ b/mon-pix/tests/unit/routes/reset-password-test.js @@ -83,14 +83,16 @@ 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, }); @@ -98,6 +100,16 @@ module('Unit | Route | reset-password', function (hooks) { 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); @@ -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); + }); }); }); });