accounts-frontend/tests-e2e/cypress/integration/profile/change-password.test.ts

90 lines
3.1 KiB
TypeScript
Raw Normal View History

2019-12-29 17:57:44 +05:30
import { openSectionByName, confirmWithPassword } from './utils';
describe('Profile — Change password', () => {
2020-05-24 04:38:24 +05:30
it('should change password', () => {
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
cy.server();
cy.route({
method: 'POST',
url: `/api/v1/accounts/${account.id}/password`,
}).as('password');
cy.visit('/');
2019-12-29 17:57:44 +05:30
2020-05-24 04:38:24 +05:30
openSectionByName('Password');
2019-12-29 17:57:44 +05:30
2020-05-24 04:38:24 +05:30
cy.location('pathname').should('eq', '/profile/change-password');
2020-05-24 04:38:24 +05:30
cy.get('[name=newPassword]').type(account.password);
cy.get('[name=newRePassword]').type(account.password);
cy.get('[name=logoutAll]').should('be.checked');
cy.get('[type=submit]').click();
2019-12-29 17:57:44 +05:30
2020-05-24 04:38:24 +05:30
cy.wait('@password')
.its('requestBody')
.should(
'eq',
new URLSearchParams({
password: '',
newPassword: account.password,
newRePassword: account.password,
logoutAll: '1',
}).toString(),
);
2019-12-29 17:57:44 +05:30
2020-05-24 04:38:24 +05:30
confirmWithPassword(account.password);
2019-12-29 17:57:44 +05:30
2020-05-24 04:38:24 +05:30
cy.wait('@password')
.its('requestBody')
.should(
'eq',
new URLSearchParams({
password: account.password,
newPassword: account.password,
newRePassword: account.password,
logoutAll: '1',
}).toString(),
);
2019-12-29 17:57:44 +05:30
2020-05-24 04:38:24 +05:30
cy.location('pathname').should('eq', '/');
});
2019-12-29 17:57:44 +05:30
});
2020-05-24 04:38:24 +05:30
it('should close password popup if form has errors', () => {
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
cy.server();
cy.route({
method: 'POST',
url: `/api/v1/accounts/${account.id}/password`,
response: {
success: false,
errors: {
password: 'force popup to be shown',
},
},
}).as('password');
cy.visit('/');
2020-05-24 04:38:24 +05:30
openSectionByName('Password');
2020-05-24 04:38:24 +05:30
cy.location('pathname').should('eq', '/profile/change-password');
2020-05-24 04:38:24 +05:30
cy.get('[name=newPassword]').type(account.password);
// make a mistake to hide confirm popup in future
cy.get('[name=newRePassword]').type(`${account.password}lol`);
cy.get('[name=logoutAll]').should('be.checked');
cy.get('[type=submit]').click();
2020-05-24 04:38:24 +05:30
// disable response mocks
cy.route({
method: 'POST',
url: `/api/v1/accounts/${account.id}/password`,
}).as('password');
2020-05-24 04:38:24 +05:30
confirmWithPassword(account.password);
2020-05-24 04:38:24 +05:30
cy.findByTestId('password-request-form').should('not.be.visible');
cy.contains('The passwords does not match').should('be.visible');
});
});
2019-12-29 17:57:44 +05:30
});