Refactor account deletion E2E tests: extract to dedicated deleteAccount.spec.ts file

This commit is contained in:
MartinBraquet
2026-04-05 14:30:24 +02:00
parent 4dd22b4194
commit 1f988d0f98
3 changed files with 40 additions and 39 deletions

View File

@@ -1,6 +1,9 @@
import {test as base} from '@playwright/test'
import {seedUser} from '../../utils/seedDatabase'
import {App} from '../pages/app'
import {testAccounts, UserAccountInformation} from '../utils/accountInformation'
import {deleteUser} from '../utils/deleteUser'
export const test = base.extend<{
app: App
@@ -8,14 +11,37 @@ export const test = base.extend<{
fakerAccount: UserAccountInformation
googleAccountOne: UserAccountInformation
googleAccountTwo: UserAccountInformation
signedInAccount: UserAccountInformation
signedOutAccount: UserAccountInformation
}>({
app: async ({page}, use) => {
const appPage = new App(page)
await use(appPage)
},
dev_one_account: async ({}, use) => {
const account = testAccounts.dev_one_account()
signedInAccount: async ({app}: {app: App}, use) => {
const account = testAccounts.faker_account()
await seedUser(
account.email,
account.password,
undefined,
account.display_name,
account.username,
)
await app.signinWithEmail(account)
await use(account)
await deleteUser('Email/Password', account)
},
signedOutAccount: async ({app}: {app: App}, use) => {
const account = testAccounts.faker_account()
await seedUser(
account.email,
account.password,
undefined,
account.display_name,
account.username,
)
await use(account)
await deleteUser('Email/Password', account)
},
fakerAccount: async ({}, use) => {
const account = testAccounts.faker_account()

View File

@@ -1,32 +1,26 @@
import {dbUserExists} from '../../utils/databaseUtils'
import {firebaseUserExists} from '../../utils/firebaseUtils'
import {seedUser} from '../../utils/seedDatabase'
import {expect, test} from '../fixtures/signInFixture'
import {testAccounts} from '../utils/accountInformation'
test.describe('delete account', () => {
test('should successfully delete an account created via email and password', async ({app}) => {
const deleteAccount = testAccounts.faker_account()
await seedUser(
deleteAccount.email,
deleteAccount.password,
undefined,
deleteAccount.display_name,
deleteAccount.username,
)
await app.signinWithEmail(deleteAccount)
test('should successfully delete an account created via email and password', async ({
app,
signedInAccount: account,
}) => {
await app.deleteProfileFromSettings()
const firebaseUserId = await firebaseUserExists(deleteAccount.email, deleteAccount.password)
const firebaseUserId = await firebaseUserExists(account.email, account.password)
expect(firebaseUserId).toBeUndefined()
const dbExists = await dbUserExists(deleteAccount.username)
const dbExists = await dbUserExists(account.username)
expect(dbExists).toBe(false)
})
test('should successfully delete an account created via google auth', async ({app, headless}) => {
test.skip(headless, 'Google popup auth test requires headed mode')
// Cannot sign in programmatically with Google
const deleteAccount = testAccounts.faker_account()
await app.home.goToRegisterPage()
await app.auth.signInToGoogleAccount(

View File

@@ -1,38 +1,19 @@
import {seedUser} from '../../utils/seedDatabase'
import {expect, test} from '../fixtures/signInFixture'
import {testAccounts} from '../utils/accountInformation'
//Seed the account
test.beforeAll(async () => {
const dev_1_Account = testAccounts.dev_one_account()
try {
await seedUser(
dev_1_Account.email,
dev_1_Account.password,
undefined,
dev_1_Account.display_name,
dev_1_Account.username,
)
} catch (_e) {
console.log('User already exists for signinFixture', dev_1_Account.email)
}
})
test.describe('when given valid input', () => {
test('should be able to sign in to an available account', async ({app, dev_one_account}) => {
await app.signinWithEmail(dev_one_account)
test('should be able to sign in to an available account', async ({app, signedInAccount}) => {
await app.home.goToHomePage()
await app.home.verifySignedInHomePage(dev_one_account.display_name)
await app.home.verifySignedInHomePage(signedInAccount.display_name)
})
})
test.describe('when given invalid input', () => {
test('should not be able to sign in to an available account', async ({
app,
dev_one_account,
signedOutAccount,
page,
}) => {
await app.signinWithEmail(dev_one_account.email, 'ThisPassword')
await app.signinWithEmail(signedOutAccount.email, 'ThisPassword')
await expect(
page.getByText('Failed to sign in with your email and password', {exact: true}),
).toBeVisible()