accounts-frontend/tests-e2e/cypress/integration/auth/forgot-password.test.ts

222 lines
5.3 KiB
TypeScript
Raw Normal View History

2019-12-28 02:10:26 +05:30
import { account1 } from '../../fixtures/accounts.json';
2019-12-28 15:55:44 +05:30
describe('Forgot / reset password', () => {
it('should request password reset', () => {
const captchaCode = 'captchaCode';
const emailMask = 'fo*@gm*l.**m';
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.server();
cy.route({
method: 'POST',
url: '/api/authentication/forgot-password',
response: {
success: true,
data: {
emailMask,
},
},
}).as('forgot');
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.visit('/');
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.get('[name=login]').type(`${account1.username}{enter}`);
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.location('pathname').should('eq', '/password');
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.getByTestId('auth-controls-secondary')
.contains('Forgot password')
.click();
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.location('pathname').should('eq', '/forgot-password');
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.getByTestId('forgot-password-login').should(
'contain',
account1.username,
2019-12-28 02:10:26 +05:30
);
2019-12-28 15:55:44 +05:30
cy.window().should('have.property', 'e2eCaptchaSetCode');
cy.window().then(win => {
// fake captcha response
// @ts-ignore
win.e2eCaptchaSetCode(captchaCode);
});
cy.get('[type=submit]')
.should('have.length', 1)
.click();
cy.wait('@forgot')
.its('requestBody')
.should(
'eq',
new URLSearchParams({
login: account1.username,
captcha: captchaCode,
}).toString(),
);
cy.location('pathname').should('eq', '/recover-password');
cy.getByTestId('auth-body').should('contain', emailMask);
});
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
it('should allow change login', () => {
const captchaCode = 'captchaCode';
const login = 'foo';
const emailMask = 'fo*@gm*l.**m';
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.server();
cy.route({
method: 'POST',
url: '/api/authentication/forgot-password',
response: {
success: true,
data: {
emailMask,
},
2019-12-28 02:10:26 +05:30
},
2019-12-28 15:55:44 +05:30
}).as('forgot');
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.visit('/');
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.get('[name=login]').type(`${account1.username}{enter}`);
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.location('pathname').should('eq', '/password');
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.getByTestId('auth-controls-secondary')
.contains('Forgot password')
.click();
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.location('pathname').should('eq', '/forgot-password');
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.getByTestId('edit-login').click();
cy.get('[name=login]').should('have.value', account1.username);
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.get('[name=login]').type(`{selectall}${login}`);
cy.window().should('have.property', 'e2eCaptchaSetCode');
cy.window().then(win => {
// fake captcha response
// @ts-ignore
win.e2eCaptchaSetCode(captchaCode);
});
cy.get('[type=submit]')
.should('have.length', 1)
.click();
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.wait('@forgot')
.its('requestBody')
.should(
'eq',
new URLSearchParams({
login,
captcha: captchaCode,
}).toString(),
);
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.location('pathname').should('eq', '/recover-password');
2019-12-28 02:10:26 +05:30
});
2019-12-28 15:55:44 +05:30
it('should allow enter login', () => {
const captchaCode = 'captchaCode';
const login = 'foo';
const emailMask = 'fo*@gm*l.**m';
2019-12-28 02:10:26 +05:30
2019-12-28 15:55:44 +05:30
cy.server();
2019-12-28 02:10:26 +05:30
cy.route({
method: 'POST',
2019-12-28 15:55:44 +05:30
url: '/api/authentication/forgot-password',
response: {
success: true,
data: {
emailMask,
},
},
}).as('forgot');
cy.visit('/forgot-password');
cy.get('[name=login]').type(login);
cy.window().should('have.property', 'e2eCaptchaSetCode');
cy.window().then(win => {
// fake captcha response
// @ts-ignore
win.e2eCaptchaSetCode(captchaCode);
});
cy.get('[type=submit]')
.should('have.length', 1)
.click();
cy.wait('@forgot')
.its('requestBody')
.should(
'eq',
new URLSearchParams({
login,
captcha: captchaCode,
}).toString(),
);
cy.location('pathname').should('eq', '/recover-password');
2019-12-28 02:10:26 +05:30
});
2019-12-28 15:55:44 +05:30
it('should recover password', () => {
const key = 'key';
const newPassword = 'newPassword';
cy.server();
cy.login({
accounts: ['default'],
updateState: false,
rawApiResp: true,
}).then(({ accounts: [account] }) => {
cy.route({
method: 'POST',
url: '/api/authentication/recover-password',
response: account,
}).as('recover');
});
cy.visit('/');
cy.get('[name=login]').type(`${account1.username}{enter}`);
cy.location('pathname').should('eq', '/password');
cy.getByTestId('auth-controls-secondary')
.contains('Forgot password')
.click();
cy.location('pathname').should('eq', '/forgot-password');
cy.getByTestId('auth-controls-secondary')
.contains('Already have')
.click();
cy.location('pathname').should('eq', '/recover-password');
cy.getByTestId('auth-controls-secondary')
.contains('Contact support')
.click();
cy.getByTestId('feedbackPopup').should('be.visible');
cy.getByTestId('feedback-popup-close').click();
cy.getByTestId('feedbackPopup').should('not.be.visible');
cy.get('[name=key]').type(key);
cy.get('[name=newPassword]').type(newPassword);
cy.get('[name=newRePassword]').type(newPassword);
cy.get('[type=submit]')
.should('have.length', 1)
.click();
cy.wait('@recover')
.its('requestBody')
.should(
'eq',
new URLSearchParams({
key,
newPassword,
newRePassword: newPassword,
}).toString(),
);
});
2019-12-28 02:10:26 +05:30
});