mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-28 16:00:24 +05:30
93 lines
2.5 KiB
TypeScript
93 lines
2.5 KiB
TypeScript
|
describe('Change username', () => {
|
||
|
it('should change username', () => {
|
||
|
cy.server();
|
||
|
|
||
|
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
|
||
|
cy.route({
|
||
|
method: 'GET',
|
||
|
url: `/api/v1/accounts/${account.id}`,
|
||
|
response: {
|
||
|
id: 7,
|
||
|
uuid: '522e8c19-89d8-4a6d-a2ec-72ebb58c2dbe',
|
||
|
username: 'FooBar',
|
||
|
isOtpEnabled: false,
|
||
|
registeredAt: 1475568334,
|
||
|
lang: 'en',
|
||
|
elyProfileLink: 'http://ely.by/u7',
|
||
|
email: 'danilenkos@auroraglobal.com',
|
||
|
isActive: true,
|
||
|
passwordChangedAt: 1476075696,
|
||
|
hasMojangUsernameCollision: true,
|
||
|
shouldAcceptRules: false,
|
||
|
},
|
||
|
});
|
||
|
|
||
|
cy.route({
|
||
|
method: 'POST',
|
||
|
url: `/api/v1/accounts/${account.id}/username`,
|
||
|
}).as('username');
|
||
|
|
||
|
cy.visit('/');
|
||
|
|
||
|
cy.getByTestId('profile-item')
|
||
|
.contains('Nickname')
|
||
|
.closest('[data-testid="profile-item"]')
|
||
|
.getByTestId('profile-action')
|
||
|
.click();
|
||
|
|
||
|
cy.location('pathname').should('eq', '/profile/change-username');
|
||
|
|
||
|
cy.get('[name=username]').type(`{selectall}${account.username}{enter}`);
|
||
|
|
||
|
cy.wait('@username')
|
||
|
.its('requestBody')
|
||
|
.should(
|
||
|
'eq',
|
||
|
new URLSearchParams({
|
||
|
username: account.username,
|
||
|
password: '',
|
||
|
}).toString(),
|
||
|
);
|
||
|
cy.getByTestId('password-request-form').should('be.visible');
|
||
|
|
||
|
// unmock accounts route
|
||
|
cy.route({
|
||
|
method: 'GET',
|
||
|
url: `/api/v1/accounts/${account.id}`,
|
||
|
});
|
||
|
|
||
|
cy.get('[name=password]').type(account.password);
|
||
|
cy.getByTestId('password-request-form')
|
||
|
.find('[type=submit]')
|
||
|
.click();
|
||
|
|
||
|
cy.wait('@username')
|
||
|
.its('requestBody')
|
||
|
.should(
|
||
|
'eq',
|
||
|
new URLSearchParams({
|
||
|
username: account.username,
|
||
|
password: account.password,
|
||
|
}).toString(),
|
||
|
);
|
||
|
|
||
|
cy.location('pathname').should('eq', '/');
|
||
|
cy.getByTestId('profile-item').should('contain', account.username);
|
||
|
cy.getByTestId('toolbar')
|
||
|
.contains(account.username)
|
||
|
.click();
|
||
|
cy.getByTestId('active-account').should('contain', account.username);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it('should go back to profile', () => {
|
||
|
cy.login({ accounts: ['default'] });
|
||
|
|
||
|
cy.visit('/profile/change-username');
|
||
|
|
||
|
cy.getByTestId('back-to-profile').click();
|
||
|
|
||
|
cy.location('pathname').should('eq', '/');
|
||
|
});
|
||
|
});
|