diff --git a/test/cypress/integration/login/recoverPassword.spec.js b/test/cypress/integration/login/recoverPassword.spec.js index 249de903e..93f135832 100755 --- a/test/cypress/integration/login/recoverPassword.spec.js +++ b/test/cypress/integration/login/recoverPassword.spec.js @@ -53,42 +53,65 @@ describe('Recover Password', () => { }); }); - /* ==== Test Created with Cypress Studio ==== */ - describe.only('Use SMS', () => { - it('Success', () => { - cy.get('.q-mt-md').click(); - cy.get('[data-cy="User or recovery email_input"]').clear().type('developer'); - cy.get('.q-mt-lg > .q-btn > .q-btn__content > .block').click(); - cy.get('[data-cy="recoverPassword.verificationPhone_input"]') - .clear() - .type('432978106'); - cy.get('.q-mt-lg > .q-btn > .q-btn__content > .block').click(); - cy.get('[data-cy="recoverPassword.verificationCode_input"]') - .clear() - .type(1234); - cy.get('.q-mt-lg > .q-btn > .q-btn__content > .block').click(); - /* ==== End Cypress Studio ==== */ + describe('Use SMS', () => { + const userWithRecoverPhone = 'developer'; + const userWithoutRecoverPhone = 'trainee'; + const wrongPhoneNumber = '432978103'; + const rightPhoneNumber = '432978106'; + const rightCode = '1234'; + const wrongCode = '1234'; + beforeEach(() => {}); + it('Without recovery phone', () => { + cy.get('input[aria-label="Username"]').type(userWithoutRecoverPhone); + cy.get(`a[href="#/recoverPassword?user=${userWithoutRecoverPhone}"]`).click(); + cy.dataCy('recoverPasswordSubmitBtn').click(); + cy.checkNotification('Account has not recovery phone available'); + }); + it('With recovery phone', () => { + cy.get('input[aria-label="Username"]').type(userWithRecoverPhone); + cy.get(`a[href="#/recoverPassword?user=${userWithRecoverPhone}"]`).click(); + cy.dataCy('recoverPasswordSubmitBtn').click(); + cy.get('[data-cy="Verification phone_input"]').clear().type(wrongPhoneNumber); + cy.dataCy('recoverPasswordSubmitBtn').click(); + cy.checkNotification('Account has not recovery phone available'); + cy.get('[data-cy="Verification phone_input"]').clear().type(rightPhoneNumber); + cy.dataCy('recoverPasswordSubmitBtn').click(); + cy.get('[data-cy="Verification code_input"]').clear().type(wrongCode); + const bodyError = { + error: { + message: 'Código de verificación incorrecto o expirado', + name: 'UserError', + statusCode: 400, + }, + }; + cy.intercept('POST', '/api/VnUsers/recoverPasswordSMS', { + statusCode: 400, + body: bodyError, + }).as('sendCode'); + cy.dataCy('recoverPasswordSubmitBtn').click(); + cy.wait('@sendCode').then((interception) => { + expect(interception.response.statusCode).to.equal(400); + cy.checkNotification(bodyError.error.message); + }); + cy.get('[data-cy="Verification code_input"]').clear().type(rightCode); + const bodySuccess = { + token: { + id: 'VXaCdjJEVLbXLqgbbjngAw9buqv8qI7ykciTNuHOMqyKvfwTm0rWqlqsLs39Riwc', + ttl: 1209600, + created: '2025-04-28T08:07:01.106Z', + userId: 9, + }, + }; + cy.intercept('POST', '/api/VnUsers/recoverPasswordSMS', { + statusCode: 200, + body: bodySuccess, + }).as('sendToken'); + cy.dataCy('recoverPasswordSubmitBtn').click(); + cy.wait('@sendToken').then((interception) => { + expect(interception.response.statusCode).to.equal(200); + + expect(interception.response.body).to.have.ownProperty('token'); + }); }); }); - - /* ==== Test Created with Cypress Studio ==== */ - it.skip('x', () => { - /* ==== Generated with Cypress Studio ==== */ - cy.get('.q-mt-md').click(); - cy.get('[data-cy="User or recovery email_input"]').clear('d'); - cy.get('[data-cy="User or recovery email_input"]').type('developer'); - cy.get('.q-mt-lg > .q-btn > .q-btn__content > .block').click(); - cy.get('[data-cy="recoverPassword.verificationPhone_input"]').clear(); - cy.get('[data-cy="recoverPassword.verificationPhone_input"]').type('43297806'); - cy.get('.q-mt-lg > .q-btn > .q-btn__content > .block').click(); - cy.get('.q-mt-lg > .q-btn > .q-btn__content > .block').click(); - cy.get('[data-cy="recoverPassword.verificationPhone_input"]').click(); - cy.get('[data-cy="recoverPassword.verificationPhone_input"]').click(); - cy.get('[data-cy="recoverPassword.verificationPhone_input"]').click(); - cy.get('[data-cy="recoverPassword.verificationPhone_input"]').click(); - cy.get('#switchLanguage').click(); - cy.get('.q-menu > :nth-child(2) > .q-item').click(); - cy.get('.q-mt-lg > .q-btn > .q-btn__content > .block').click(); - /* ==== End Cypress Studio ==== */ - }); });