From 95a62c29be7968c1f9420b3b7d72486365d526eb Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Mon, 4 Nov 2024 11:00:13 +0100 Subject: [PATCH 1/5] refactor(mon-pix): rename reset-password and password-reset-demand routes unit test --- .../{password-reset-test.js => password-reset-demand-test.js} | 2 +- .../{reset-password-demand-test.js => reset-password-test.js} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename mon-pix/tests/unit/routes/{password-reset-test.js => password-reset-demand-test.js} (81%) rename mon-pix/tests/unit/routes/{reset-password-demand-test.js => reset-password-test.js} (97%) diff --git a/mon-pix/tests/unit/routes/password-reset-test.js b/mon-pix/tests/unit/routes/password-reset-demand-test.js similarity index 81% rename from mon-pix/tests/unit/routes/password-reset-test.js rename to mon-pix/tests/unit/routes/password-reset-demand-test.js index 67c0ea8a658..63ee067a3e0 100644 --- a/mon-pix/tests/unit/routes/password-reset-test.js +++ b/mon-pix/tests/unit/routes/password-reset-demand-test.js @@ -1,7 +1,7 @@ import { setupTest } from 'ember-qunit'; import { module, test } from 'qunit'; -module('Unit | Route | password reset', function (hooks) { +module('Unit | Route | password-reset-demand', function (hooks) { setupTest(hooks); let route; diff --git a/mon-pix/tests/unit/routes/reset-password-demand-test.js b/mon-pix/tests/unit/routes/reset-password-test.js similarity index 97% rename from mon-pix/tests/unit/routes/reset-password-demand-test.js rename to mon-pix/tests/unit/routes/reset-password-test.js index 12bc7313aa7..7601ac5f8e1 100644 --- a/mon-pix/tests/unit/routes/reset-password-demand-test.js +++ b/mon-pix/tests/unit/routes/reset-password-test.js @@ -3,7 +3,7 @@ import { setupTest } from 'ember-qunit'; import { module, test } from 'qunit'; import sinon from 'sinon'; -module('Unit | Route | changer mot de passe', function (hooks) { +module('Unit | Route | reset-password', function (hooks) { setupTest(hooks); module('Route behavior', function (hooks) { From 61445b7791c9dac73c4bf2412014777d6f0e2f21 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Mon, 4 Nov 2024 11:56:45 +0100 Subject: [PATCH 2/5] refactor(mon-pix): add unit test for reset password route for handling a server error case --- .../tests/unit/routes/reset-password-test.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/mon-pix/tests/unit/routes/reset-password-test.js b/mon-pix/tests/unit/routes/reset-password-test.js index 7601ac5f8e1..7f288010bf0 100644 --- a/mon-pix/tests/unit/routes/reset-password-test.js +++ b/mon-pix/tests/unit/routes/reset-password-test.js @@ -1,10 +1,14 @@ import Service from '@ember/service'; +import { t } from 'ember-intl/test-support'; import { setupTest } from 'ember-qunit'; import { module, test } from 'qunit'; import sinon from 'sinon'; +import setupIntl from '../../helpers/setup-intl'; + module('Unit | Route | reset-password', function (hooks) { setupTest(hooks); + setupIntl(hooks); module('Route behavior', function (hooks) { let storeStub; @@ -78,5 +82,31 @@ module('Unit | Route | reset-password', function (hooks) { assert.deepEqual(result.temporaryKey, params.temporary_key); }); }); + 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 + 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({ + replaceWith: replaceWithStub, + }); + + queryRecordStub.rejects({ errors }); + route.set('store', storeStub); + route.set('router', routerStub); + + // when + await route.model(params); + + // then + sinon.assert.calledOnceWithExactly(replaceWithStub, 'password-reset-demand'); + assert.strictEqual(errorsService.errors.length, 1); + assert.strictEqual(errorsService.errors[0], t('pages.reset-password.error.expired-demand')); + }); + }); + }); }); }); From 2964768abb6ff656560235ece1aeb1d4fdd64c13 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Mon, 4 Nov 2024 14:31:38 +0100 Subject: [PATCH 3/5] 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); + }); }); }); }); From 5537ca889cc33388d6abac0755c0dd4c483b3cc4 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Tue, 29 Oct 2024 17:33:51 +0100 Subject: [PATCH 4/5] feat(mon-pix): handle errors service in PasswordResetDemandForm component --- .../password-reset-demand-form.gjs | 5 ++++- .../password-reset-demand-form-test.gjs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs b/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs index 098ff4a51d6..2d543f49e92 100644 --- a/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs +++ b/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs @@ -4,6 +4,7 @@ import PixInput from '@1024pix/pix-ui/components/pix-input'; import PixMessage from '@1024pix/pix-ui/components/pix-message'; import { on } from '@ember/modifier'; import { action } from '@ember/object'; +import { service } from '@ember/service'; import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; import { t } from 'ember-intl'; @@ -14,8 +15,10 @@ import isEmailValid from '../../../utils/email-validator.js'; import PasswordResetDemandReceivedInfo from './password-reset-demand-received-info'; export default class PasswordResetDemandForm extends Component { + @service errors; + + @tracked globalError = this.errors.hasErrors && this.errors.shift(); @tracked isLoading = false; - @tracked globalError; @tracked isPasswordResetDemandReceived = false; validation = new FormValidation({ diff --git a/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs b/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs index 87548117b15..aedba90906e 100644 --- a/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs +++ b/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs @@ -178,6 +178,21 @@ module('Integration | Component | Authentication | PasswordResetDemand | passwor assert.dom(screen.queryByText(t('common.api-error-messages.internal-server-error'))).exists(); }); }); + + module('when there is an error in errors service', function () { + test('it displays the error on the corresponding banner', async function (assert) { + // given + const errorKeyMessageToBeDisplayed = 'pages.reset-password.error.expired-demand'; + const errorsService = this.owner.lookup('service:errors'); + + // when + errorsService.push(errorKeyMessageToBeDisplayed); + const screen = await render(); + + // then + assert.dom(screen.getByRole('alert', { value: t(errorKeyMessageToBeDisplayed) })).exists(); + }); + }); }); }); From cfb64f5193abfd0d61c89c0be76f03ecb6e75d26 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Mon, 4 Nov 2024 14:56:09 +0100 Subject: [PATCH 5/5] feat(mon-pix): adjust sso selection signup link --- mon-pix/app/styles/pages/_sso-selection.scss | 2 ++ mon-pix/app/templates/authentication/sso-selection.hbs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mon-pix/app/styles/pages/_sso-selection.scss b/mon-pix/app/styles/pages/_sso-selection.scss index 9ed5b5197dd..4d2d9b8cbe2 100644 --- a/mon-pix/app/styles/pages/_sso-selection.scss +++ b/mon-pix/app/styles/pages/_sso-selection.scss @@ -5,6 +5,8 @@ padding-top: var(--pix-spacing-6x); &__signup { + @extend %pix-body-m; + display: flex; gap: var(--pix-spacing-2x); margin-top: var(--pix-spacing-4x); diff --git a/mon-pix/app/templates/authentication/sso-selection.hbs b/mon-pix/app/templates/authentication/sso-selection.hbs index 565eb2db943..935dccec84e 100644 --- a/mon-pix/app/templates/authentication/sso-selection.hbs +++ b/mon-pix/app/templates/authentication/sso-selection.hbs @@ -22,7 +22,7 @@ {{#if this.isSigninRoute}} {{/if}}