mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-23 13:39:54 +05:30
Cover delete/restore account forms with E2E tests
This commit is contained in:
parent
8ee2323bfa
commit
3cff6ad26c
@ -22,7 +22,7 @@ const AccountDeleted: ComponentType<Props> = ({ onRestore }) => {
|
||||
}, [onRestore]);
|
||||
|
||||
return (
|
||||
<div className={styles.wrapper}>
|
||||
<div className={styles.wrapper} data-testid="deletedAccount">
|
||||
<Message key="accountDeleted" defaultMessage="Account is deleted">
|
||||
{(pageTitle: string) => (
|
||||
<h2 className={styles.title}>
|
||||
|
@ -193,8 +193,14 @@ const Profile: ComponentType<Props> = ({ user, activeLocale }) => {
|
||||
|
||||
<ProfileField
|
||||
value={
|
||||
// @ts-ignore
|
||||
<Button component={Link} to="/profile/delete" small color="black">
|
||||
<Button
|
||||
component={Link}
|
||||
// @ts-ignore
|
||||
to="/profile/delete"
|
||||
small
|
||||
color="black"
|
||||
data-testid="profile-action"
|
||||
>
|
||||
<Message key="accountDeletion" defaultMessage="Account deletion" />
|
||||
</Button>
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ export interface UserResponse {
|
||||
id: number;
|
||||
isActive: boolean;
|
||||
isOtpEnabled: boolean;
|
||||
isDeleted: boolean;
|
||||
lang: string;
|
||||
passwordChangedAt: number; // timestamp
|
||||
registeredAt: number; // timestamp
|
||||
@ -16,13 +17,7 @@ export interface UserResponse {
|
||||
}
|
||||
|
||||
export function getInfo(id: number, token?: string): Promise<UserResponse> {
|
||||
return request.get(
|
||||
`/api/v1/accounts/${id}`,
|
||||
{},
|
||||
{
|
||||
token,
|
||||
},
|
||||
);
|
||||
return request.get(`/api/v1/accounts/${id}`, {}, { token });
|
||||
}
|
||||
|
||||
export function changePassword(
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { UserResponse } from 'app/services/api/accounts';
|
||||
|
||||
import { openSectionByName, confirmWithPassword } from './utils';
|
||||
|
||||
describe('Profile — Change Username', () => {
|
||||
@ -18,10 +20,11 @@ describe('Profile — Change Username', () => {
|
||||
elyProfileLink: 'http://ely.by/u7',
|
||||
email: 'danilenkos@auroraglobal.com',
|
||||
isActive: true,
|
||||
isDeleted: false,
|
||||
passwordChangedAt: 1476075696,
|
||||
hasMojangUsernameCollision: true,
|
||||
shouldAcceptRules: false,
|
||||
},
|
||||
} as UserResponse,
|
||||
});
|
||||
|
||||
cy.route({
|
||||
|
75
tests-e2e/cypress/integration/profile/delete-account.test.ts
Normal file
75
tests-e2e/cypress/integration/profile/delete-account.test.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import { openSectionByName, confirmWithPassword } from './utils';
|
||||
import { UserResponse } from 'app/services/api/accounts';
|
||||
|
||||
describe('Profile — Delete account', () => {
|
||||
it('should delete account', () => {
|
||||
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
|
||||
cy.server();
|
||||
cy.route({
|
||||
method: 'DELETE',
|
||||
url: `/api/v1/accounts/${account.id}`,
|
||||
}).as('deleteAccount');
|
||||
cy.route({
|
||||
method: 'GET',
|
||||
url: `/api/v1/accounts/${account.id}`,
|
||||
});
|
||||
|
||||
cy.visit('/');
|
||||
|
||||
openSectionByName('Account deletion');
|
||||
|
||||
cy.location('pathname').should('eq', '/profile/delete');
|
||||
|
||||
cy.get('[type=submit]').click();
|
||||
|
||||
cy.wait('@deleteAccount')
|
||||
.its('requestBody')
|
||||
.should(
|
||||
'eq',
|
||||
new URLSearchParams({
|
||||
password: '',
|
||||
}).toString(),
|
||||
);
|
||||
|
||||
cy.route({
|
||||
method: 'DELETE',
|
||||
url: `/api/v1/accounts/${account.id}`,
|
||||
response: { success: true },
|
||||
}).as('deleteAccount');
|
||||
cy.route({
|
||||
method: 'GET',
|
||||
url: `/api/v1/accounts/${account.id}`,
|
||||
response: {
|
||||
id: 7,
|
||||
uuid: '522e8c19-89d8-4a6d-a2ec-72ebb58c2dbe',
|
||||
username: 'SleepWalker',
|
||||
isOtpEnabled: false,
|
||||
registeredAt: 1475568334,
|
||||
lang: 'en',
|
||||
elyProfileLink: 'http://ely.by/u7',
|
||||
email: 'danilenkos@auroraglobal.com',
|
||||
isActive: true,
|
||||
isDeleted: true, // mock deleted state since the delete will not perform the real request
|
||||
passwordChangedAt: 1476075696,
|
||||
hasMojangUsernameCollision: true,
|
||||
shouldAcceptRules: false,
|
||||
} as UserResponse,
|
||||
});
|
||||
|
||||
confirmWithPassword(account.password);
|
||||
|
||||
cy.wait('@deleteAccount')
|
||||
.its('requestBody')
|
||||
.should(
|
||||
'eq',
|
||||
new URLSearchParams({
|
||||
password: account.password,
|
||||
}).toString(),
|
||||
);
|
||||
|
||||
cy.location('pathname').should('eq', '/');
|
||||
|
||||
cy.findByTestId('deletedAccount').should('contain', 'Account is deleted');
|
||||
});
|
||||
});
|
||||
});
|
@ -1,3 +1,5 @@
|
||||
import { UserResponse } from 'app/services/api/accounts';
|
||||
|
||||
import { openSectionByName, getSectionByName, confirmWithPassword } from './utils';
|
||||
|
||||
describe('Profile — mfa', () => {
|
||||
@ -63,10 +65,11 @@ describe('Profile — mfa', () => {
|
||||
elyProfileLink: 'http://ely.by/u7',
|
||||
email: 'danilenkos@auroraglobal.com',
|
||||
isActive: true,
|
||||
isDeleted: false,
|
||||
passwordChangedAt: 1476075696,
|
||||
hasMojangUsernameCollision: true,
|
||||
shouldAcceptRules: false,
|
||||
},
|
||||
} as UserResponse,
|
||||
});
|
||||
|
||||
confirmWithPassword(account.password);
|
||||
@ -104,10 +107,11 @@ describe('Profile — mfa', () => {
|
||||
elyProfileLink: 'http://ely.by/u7',
|
||||
email: 'danilenkos@auroraglobal.com',
|
||||
isActive: true,
|
||||
isDeleted: false,
|
||||
passwordChangedAt: 1476075696,
|
||||
hasMojangUsernameCollision: true,
|
||||
shouldAcceptRules: false,
|
||||
},
|
||||
} as UserResponse,
|
||||
});
|
||||
cy.route({
|
||||
method: 'DELETE',
|
||||
|
@ -0,0 +1,63 @@
|
||||
import { UserResponse } from 'app/services/api/accounts';
|
||||
|
||||
describe('Profile — Restore account', () => {
|
||||
it('should restore account', () => {
|
||||
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
|
||||
cy.server();
|
||||
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,
|
||||
isDeleted: true, // force deleted state
|
||||
passwordChangedAt: 1476075696,
|
||||
hasMojangUsernameCollision: true,
|
||||
shouldAcceptRules: false,
|
||||
} as UserResponse,
|
||||
});
|
||||
cy.route({
|
||||
method: 'POST',
|
||||
url: `/api/v1/accounts/${account.id}/restore`,
|
||||
response: { success: true },
|
||||
}).as('restoreAccount');
|
||||
|
||||
cy.visit('/');
|
||||
|
||||
cy.route({
|
||||
method: 'GET',
|
||||
url: `/api/v1/accounts/${account.id}`,
|
||||
response: {
|
||||
id: 7,
|
||||
uuid: '522e8c19-89d8-4a6d-a2ec-72ebb58c2dbe',
|
||||
username: 'SleepWalker',
|
||||
isOtpEnabled: false,
|
||||
registeredAt: 1475568334,
|
||||
lang: 'en',
|
||||
elyProfileLink: 'http://ely.by/u7',
|
||||
email: 'danilenkos@auroraglobal.com',
|
||||
isActive: true,
|
||||
isDeleted: false, // force deleted state
|
||||
passwordChangedAt: 1476075696,
|
||||
hasMojangUsernameCollision: true,
|
||||
shouldAcceptRules: false,
|
||||
} as UserResponse,
|
||||
});
|
||||
|
||||
cy.findByTestId('deletedAccount').contains('Restore account').click();
|
||||
|
||||
cy.wait('@restoreAccount');
|
||||
|
||||
cy.location('pathname').should('eq', '/');
|
||||
|
||||
cy.findByTestId('profile-index').should('contain', account.username);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user