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

165 lines
5.5 KiB
TypeScript
Raw Normal View History

import { openSectionByName, confirmWithPassword } from './utils';
describe('Profile — Change Email', () => {
2020-05-24 04:38:24 +05:30
it('should change email', () => {
const key = 'key123';
const key2 = 'key1232';
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
cy.server();
cy.route({
method: 'POST',
url: `/api/v1/accounts/${account.id}/email-verification`,
}).as('requestEmailChange');
cy.route({
method: 'POST',
url: `/api/v1/accounts/${account.id}/new-email-verification`,
response: { success: true },
}).as('verifyNewEmail');
cy.route({
method: 'POST',
url: `/api/v1/accounts/${account.id}/email`,
response: { success: true },
}).as('saveEmail');
cy.visit('/');
openSectionByName('Email');
cy.location('pathname').should('eq', '/profile/change-email');
cy.contains('Send Email').click();
cy.wait('@requestEmailChange')
.its('requestBody')
.should(
'eq',
new URLSearchParams({
password: '',
}).toString(),
);
cy.route({
method: 'POST',
url: `/api/v1/accounts/${account.id}/email-verification`,
response: { success: true },
}).as('requestEmailChange');
confirmWithPassword(account.password);
cy.wait('@requestEmailChange')
.its('requestBody')
.should(
'eq',
new URLSearchParams({
password: account.password,
}).toString(),
);
cy.location('pathname').should('eq', '/profile/change-email/step2');
cy.findByTestId('step2').should('be.visible');
cy.findByTestId('step2').find('[name=key]').type(key);
cy.findByTestId('step2').find('[name=email]').type(`${account.email}{enter}`);
cy.wait('@verifyNewEmail')
.its('requestBody')
.should(
'eq',
new URLSearchParams({
email: account.email,
key,
}).toString(),
);
cy.location('pathname').should('eq', '/profile/change-email/step3');
cy.findByTestId('step3').find('[name=key]').should('be.visible');
cy.findByTestId('step3').find('[name=key]').should('have.value', '');
cy.findByTestId('step3').find('[name=key]').type(`${key2}{enter}`);
cy.wait('@saveEmail')
.its('requestBody')
.should(
'eq',
new URLSearchParams({
key: key2,
}).toString(),
);
cy.location('pathname').should('eq', '/');
});
});
2020-05-24 04:38:24 +05:30
it('should allow to skip steps', () => {
cy.login({ accounts: ['default'] });
2020-05-24 04:38:24 +05:30
cy.visit('/profile/change-email');
2020-05-24 04:38:24 +05:30
cy.contains('Already received code').click();
2020-05-24 04:38:24 +05:30
cy.visit('/profile/change-email/step2');
2020-05-24 04:38:24 +05:30
cy.contains('Already received code').click();
2020-05-24 04:38:24 +05:30
cy.visit('/profile/change-email/step3');
});
2020-05-24 04:38:24 +05:30
it('should read code from url on step2', () => {
const key = 'key123';
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
cy.server();
cy.route({
method: 'POST',
url: `/api/v1/accounts/${account.id}/new-email-verification`,
response: { success: true },
}).as('verifyNewEmail');
cy.visit(`/profile/change-email/step2/${key}`);
cy.findByTestId('step2').find('[name=key]').should('have.value', key);
cy.findByTestId('step2').find('[name=key]').should('be.disabled');
cy.findByTestId('step2').find('[name=email]').type(`${account.email}{enter}`);
cy.wait('@verifyNewEmail')
.its('requestBody')
.should(
'eq',
new URLSearchParams({
email: account.email,
key,
}).toString(),
);
cy.location('pathname').should('eq', '/profile/change-email/step3');
cy.findByTestId('step3').find('[name=key]').should('have.value', '');
});
});
2020-05-24 04:38:24 +05:30
it('should read code from url on step3', () => {
const key = 'key123';
2020-05-24 04:38:24 +05:30
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
cy.server();
cy.route({
method: 'POST',
url: `/api/v1/accounts/${account.id}/email`,
response: { success: true },
}).as('saveEmail');
2020-05-24 04:38:24 +05:30
cy.visit(`/profile/change-email/step3/${key}`);
2020-05-24 04:38:24 +05:30
cy.findByTestId('step3').find('[name=key]').should('have.value', key);
cy.findByTestId('step3').find('[name=key]').should('be.disabled');
2020-05-24 04:38:24 +05:30
cy.findByTestId('change-email').find('[type=submit]').click();
2020-05-24 04:38:24 +05:30
cy.wait('@saveEmail').its('requestBody').should(
'eq',
new URLSearchParams({
key,
}).toString(),
);
cy.location('pathname').should('eq', '/');
});
});
});