-
Notifications
You must be signed in to change notification settings - Fork 11.8k
test: add end-to-end tests for delete own account functionality #36129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e911421
test: add end-to-end tests for account deletion functionality
jessicaschelly 44806b4
fix
jessicaschelly 2279106
fix test
jessicaschelly 5c7da3b
improve structure
jessicaschelly 855918f
create user helper and fix locator
jessicaschelly 424ea75
fix review
jessicaschelly d48989e
Merge remote-tracking branch 'origin/develop' into test/delete-own-ac…
jessicaschelly 6e9efb2
remove fails since the issue is no longer present
jessicaschelly ec449e8
Merge branch 'develop' into test/delete-own-account
jessicaschelly e0f4d37
test: add promise all
jessicaschelly 3e51c3c
lint
jessicaschelly 54e1f7e
change locators
jessicaschelly 1b42c9b
Merge branch 'develop' into test/delete-own-account
jessicaschelly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { DEFAULT_USER_CREDENTIALS } from './config/constants'; | ||
import { AccountProfile, Registration, Utils } from './page-objects'; | ||
import { ToastBar } from './page-objects/toastBar'; | ||
import { test, expect } from './utils/test'; | ||
import { createTestUser, type ITestUser } from './utils/user-helpers'; | ||
|
||
test.describe('Delete Own Account', () => { | ||
let poAccountProfile: AccountProfile; | ||
let poRegistration: Registration; | ||
let poToastBar: ToastBar; | ||
let poUtils: Utils; | ||
let userToDelete: ITestUser; | ||
let userWithInvalidPassword: ITestUser; | ||
let userWithoutPermissions: ITestUser; | ||
|
||
test.beforeAll(async ({ api }) => { | ||
const response = await api.post('/settings/Accounts_AllowDeleteOwnAccount', { value: true }); | ||
expect(response.status()).toBe(200); | ||
userToDelete = await createTestUser(api, { username: 'user-to-delete' }); | ||
userWithInvalidPassword = await createTestUser(api, { username: 'user-with-invalid-password' }); | ||
userWithoutPermissions = await createTestUser(api, { username: 'user-without-permissions' }); | ||
}); | ||
|
||
test.beforeEach(async ({ page }) => { | ||
poAccountProfile = new AccountProfile(page); | ||
poRegistration = new Registration(page); | ||
poToastBar = new ToastBar(page); | ||
poUtils = new Utils(page); | ||
await page.goto('/home'); | ||
}); | ||
|
||
test.afterAll(async ({ api }) => { | ||
const response = await api.post('/settings/Accounts_AllowDeleteOwnAccount', { value: false }); | ||
expect(response.status()).toBe(200); | ||
await userToDelete.delete(); | ||
await userWithInvalidPassword.delete(); | ||
await userWithoutPermissions.delete(); | ||
}); | ||
|
||
test('should not delete account when invalid password is provided', async ({ page }) => { | ||
await test.step('login with the user to delete', async () => { | ||
await poRegistration.username.type(userWithInvalidPassword.data.username); | ||
await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password); | ||
aleksandernsilva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await poRegistration.btnLogin.click(); | ||
await expect(poUtils.mainContent).toBeVisible(); | ||
}); | ||
|
||
await test.step('navigate to profile and locate Delete My Account button', async () => { | ||
await page.goto('/account/profile'); | ||
await poAccountProfile.profileTitle.waitFor({ state: 'visible' }); | ||
await poAccountProfile.btnDeleteMyAccount.click(); | ||
await expect(poAccountProfile.deleteAccountDialog).toBeVisible(); | ||
}); | ||
|
||
await test.step('verify delete confirmation dialog appears', async () => { | ||
await expect(poAccountProfile.deleteAccountDialogMessageWithPassword).toBeVisible(); | ||
await expect(poAccountProfile.inputDeleteAccountPassword).toBeVisible(); | ||
await expect(poAccountProfile.btnDeleteAccountConfirm).toBeVisible(); | ||
await expect(poAccountProfile.btnDeleteAccountCancel).toBeVisible(); | ||
}); | ||
|
||
await test.step('enter invalid password in the confirmation field and click delete account', async () => { | ||
await poAccountProfile.inputDeleteAccountPassword.fill('invalid-password'); | ||
await expect(poAccountProfile.inputDeleteAccountPassword).toHaveValue('invalid-password'); | ||
await poAccountProfile.btnDeleteAccountConfirm.click(); | ||
}); | ||
|
||
await test.step('verify error message appears', async () => { | ||
await expect(poToastBar.alert).toBeVisible(); | ||
await expect(poToastBar.alert).toHaveText('Invalid password [error-invalid-password]'); | ||
}); | ||
|
||
await test.step('verify user is still on the profile page', async () => { | ||
await expect(poAccountProfile.profileTitle).toBeVisible(); | ||
}); | ||
}); | ||
|
||
test('should delete account when valid password is provided and permission is enabled', async ({ page }) => { | ||
await test.step('login with the user to delete', async () => { | ||
await poRegistration.username.type(userToDelete.data.username); | ||
await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password); | ||
aleksandernsilva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await poRegistration.btnLogin.click(); | ||
await expect(poUtils.mainContent).toBeVisible(); | ||
}); | ||
|
||
await test.step('navigate to profile and locate Delete My Account button', async () => { | ||
await page.goto('/account/profile'); | ||
await poAccountProfile.profileTitle.waitFor({ state: 'visible' }); | ||
await poAccountProfile.btnDeleteMyAccount.click(); | ||
await expect(poAccountProfile.deleteAccountDialog).toBeVisible(); | ||
}); | ||
|
||
await test.step('verify delete confirmation dialog appears', async () => { | ||
await expect(poAccountProfile.deleteAccountDialogMessageWithPassword).toBeVisible(); | ||
await expect(poAccountProfile.inputDeleteAccountPassword).toBeVisible(); | ||
await expect(poAccountProfile.btnDeleteAccountConfirm).toBeVisible(); | ||
await expect(poAccountProfile.btnDeleteAccountCancel).toBeVisible(); | ||
}); | ||
|
||
await test.step('enter password in the confirmation field and click delete account', async () => { | ||
await poAccountProfile.inputDeleteAccountPassword.fill(DEFAULT_USER_CREDENTIALS.password); | ||
await expect(poAccountProfile.inputDeleteAccountPassword).toHaveValue(DEFAULT_USER_CREDENTIALS.password); | ||
await poAccountProfile.btnDeleteAccountConfirm.click(); | ||
}); | ||
|
||
await test.step('verify user is redirected to login page', async () => { | ||
await expect(poRegistration.btnLogin).toBeVisible(); | ||
userToDelete.markAsDeleted(); | ||
}); | ||
}); | ||
|
||
test.describe('Delete Own Account - Permission Disabled', () => { | ||
test.beforeAll(async ({ api }) => { | ||
const response = await api.post('/settings/Accounts_AllowDeleteOwnAccount', { value: false }); | ||
expect(response.status()).toBe(200); | ||
}); | ||
|
||
test('should not show delete account button when permission is disabled', async ({ page }) => { | ||
await test.step('login with the user to delete', async () => { | ||
await poRegistration.username.type(userWithoutPermissions.data.username); | ||
await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password); | ||
aleksandernsilva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await poRegistration.btnLogin.click(); | ||
await expect(poUtils.mainContent).toBeVisible(); | ||
}); | ||
|
||
await test.step('navigate to profile and locate Delete My Account button', async () => { | ||
await page.goto('/account/profile'); | ||
await poAccountProfile.profileTitle.waitFor({ state: 'visible' }); | ||
await expect(poAccountProfile.btnDeleteMyAccount).not.toBeVisible(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import type { APIResponse } from '@playwright/test'; | ||
import type { IUser } from '@rocket.chat/core-typings'; | ||
|
||
import type { BaseTest } from './test'; | ||
import { DEFAULT_USER_CREDENTIALS } from '../config/constants'; | ||
|
||
export interface ICreateUserOptions { | ||
username?: string; | ||
email?: string; | ||
name?: string; | ||
password?: string; | ||
roles?: string[]; | ||
} | ||
|
||
export interface ITestUser { | ||
response: APIResponse; | ||
data: IUser & { username: string }; | ||
deleted: boolean; | ||
delete: () => Promise<APIResponse | undefined>; | ||
markAsDeleted: () => void; | ||
} | ||
|
||
/** | ||
* Creates a test user with optional customizations | ||
*/ | ||
export async function createTestUser(api: BaseTest['api'], options: ICreateUserOptions = {}): Promise<ITestUser> { | ||
const userData = { | ||
email: options.email || faker.internet.email(), | ||
name: options.name || faker.person.fullName(), | ||
password: options.password || DEFAULT_USER_CREDENTIALS.password, | ||
username: options.username || `test-user-${faker.string.uuid()}`, | ||
roles: options.roles || ['user'], | ||
}; | ||
|
||
const response = await api.post('/users.create', userData); | ||
|
||
if (response.status() !== 200) { | ||
throw new Error(`Failed to create user: ${response.status()}, response: ${await response.text()}`); | ||
} | ||
|
||
const { user } = await response.json(); | ||
|
||
return { | ||
response, | ||
data: user, | ||
deleted: false, | ||
markAsDeleted(this: ITestUser) { | ||
this.deleted = true; | ||
}, | ||
async delete(this: ITestUser) { | ||
if (this.deleted) { | ||
return; | ||
} | ||
|
||
const response = await api.post('/users.delete', { userId: user._id }); | ||
this.markAsDeleted(); | ||
return response; | ||
}, | ||
}; | ||
} | ||
|
||
/** | ||
* Creates multiple test users at once | ||
*/ | ||
export async function createTestUsers(api: BaseTest['api'], count: number, options: ICreateUserOptions = {}): Promise<ITestUser[]> { | ||
const promises = Array.from({ length: count }, (_, i) => | ||
createTestUser(api, { | ||
...options, | ||
username: options.username ? `${options.username}-${i + 1}` : undefined, | ||
}), | ||
); | ||
|
||
return Promise.all(promises); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.