From d534ee423b8868d27fbc254300f3167251309fd4 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 23 May 2024 21:23:08 +0200 Subject: [PATCH] test(salix): refs #6427 improve test --- back/methods/vn-user/recover-passwordSMS.js | 15 +++++-- e2e/helpers/selectors.js | 4 ++ e2e/paths/01-salix/04_recoverPassword.spec.js | 40 +++++++++++++++++- .../components/recover-password/index.html | 41 +++++++++++-------- .../components/recover-password/index.js | 9 ++-- loopback/locale/en.json | 3 +- loopback/locale/es.json | 5 ++- 7 files changed, 88 insertions(+), 29 deletions(-) diff --git a/back/methods/vn-user/recover-passwordSMS.js b/back/methods/vn-user/recover-passwordSMS.js index bd14324d3..9a45e6486 100644 --- a/back/methods/vn-user/recover-passwordSMS.js +++ b/back/methods/vn-user/recover-passwordSMS.js @@ -35,8 +35,15 @@ module.exports = Self => { Object.assign(myOptions, options); const user = await Self.findOne({ - fields: ['id', 'userId', 'email', 'name', 'recoveryPhone'], - where: {userId} + fields: ['id', 'name', 'email', 'name', 'recoveryPhone'], + where: { + or: [ + {id: userId}, + {nickname: userId}, + {name: userId}, + {email: userId}, + ] + } }); if (!user) throw new UserError('Credentials not valid'); @@ -51,9 +58,9 @@ module.exports = Self => { const code = await authCode(user, myOptions); - if (!isProduction()) + if (isProduction(true)) return {code}; - await Self.app.models.Sms.send({req: {accessToken: {userId: id}}}, +userId, code); + await Self.app.models.Sms.send({req: {accessToken: {userId}}}, +userId, code); } catch (err) { if (err.code === 'EMAIL_NOT_FOUND') return; diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 685345273..af8f05581 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -33,7 +33,11 @@ export default { recoverPassword: { recoverPasswordButton: 'vn-login a[ui-sref="recover-password"]', email: 'vn-recover-password vn-textfield[ng-model="$ctrl.user"]', + code: 'vn-recover-password vn-textfield[ng-model="$ctrl.verificationCode"]', sendEmailButton: 'vn-recover-password vn-submit', + smsOption: 'vn-recover-password vn-radio[val="sms"]', + emailOption: 'vn-recover-password vn-radio[val="email"]', + }, accountIndex: { addAccount: 'vn-user-index button vn-icon[icon="add"]', diff --git a/e2e/paths/01-salix/04_recoverPassword.spec.js b/e2e/paths/01-salix/04_recoverPassword.spec.js index aa0389648..955877681 100644 --- a/e2e/paths/01-salix/04_recoverPassword.spec.js +++ b/e2e/paths/01-salix/04_recoverPassword.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors'; import getBrowser from '../../helpers/puppeteer'; -describe('RecoverPassword path', async() => { +fdescribe('RecoverPassword path', async() => { let browser; let page; @@ -17,8 +17,9 @@ describe('RecoverPassword path', async() => { await browser.close(); }); - it('should not throw error if not exist user', async() => { + it('should not throw error if not exist user when select email option', async() => { await page.write(selectors.recoverPassword.email, 'fakeEmail@mydomain.com'); + await page.waitToClick(selectors.recoverPassword.emailOption); await page.waitToClick(selectors.recoverPassword.sendEmailButton); const message = await page.waitForSnackbar(); @@ -26,11 +27,27 @@ describe('RecoverPassword path', async() => { expect(message.text).toContain('Notification sent!'); }); + it('should not throw error if not exist user when select sms option', async() => { + await page.waitForState('login'); + await page.waitToClick(selectors.recoverPassword.recoverPasswordButton); + await page.write(selectors.recoverPassword.email, 'fakeEmail@mydomain.com'); + await page.waitToClick(selectors.recoverPassword.emailOption); + // await page.waitToClick(selectors.recoverPassword.smsOption); + await page.waitToClick(selectors.recoverPassword.sendEmailButton); + + const message = await page.waitForSnackbar(); + // await page.waitForState('login'); + + expect(message.text).toContain('Credentials not valid'); + expect(await page.getState()).toContain('recover-password'); + }); + it('should send email using email', async() => { await page.waitForState('login'); await page.waitToClick(selectors.recoverPassword.recoverPasswordButton); await page.write(selectors.recoverPassword.email, 'BruceWayne@mydomain.com'); + await page.waitToClick(selectors.recoverPassword.emailOption); await page.waitToClick(selectors.recoverPassword.sendEmailButton); const message = await page.waitForSnackbar(); await page.waitForState('login'); @@ -43,10 +60,29 @@ describe('RecoverPassword path', async() => { await page.waitToClick(selectors.recoverPassword.recoverPasswordButton); await page.write(selectors.recoverPassword.email, 'BruceWayne'); + await page.waitToClick(selectors.recoverPassword.emailOption); await page.waitToClick(selectors.recoverPassword.sendEmailButton); const message = await page.waitForSnackbar(); await page.waitForState('login'); expect(message.text).toContain('Notification sent!'); }); + + it('should send sms using username', async() => { + await page.waitForState('login'); + await page.waitToClick(selectors.recoverPassword.recoverPasswordButton); + + await page.write(selectors.recoverPassword.email, 'BruceWayne'); + await page.waitToClick(selectors.recoverPassword.smsOption); + await page.waitToClick(selectors.recoverPassword.sendEmailButton); + const httpDataResponse = await page.waitForResponse(response => { + return response.status() === 200 && response.url().includes(`VnUsers/recoverPasswordSMS`); + }); + const {code} = await httpDataResponse.json(); + await page.write(selectors.recoverPassword.code, code); + await page.waitToClick(selectors.recoverPassword.sendEmailButton); + await page.waitForState('reset-password'); + + expect(await page.getState()).toContain('reset-password'); + }); }); diff --git a/front/salix/components/recover-password/index.html b/front/salix/components/recover-password/index.html index c6d809f86..8e329f144 100644 --- a/front/salix/components/recover-password/index.html +++ b/front/salix/components/recover-password/index.html @@ -1,9 +1,10 @@
Recover password
+ vn-focus +> + class="vn-mt-md" +> - - - - + + + +
We will sent you a sms to recover your password @@ -36,7 +41,11 @@ ng-model="$ctrl.method" >