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

This commit is contained in:
MartinBraquet
2026-04-05 14:14:43 +02:00
parent 46bad59ccb
commit 4dd22b4194
4 changed files with 64 additions and 46 deletions

View File

@@ -46,3 +46,10 @@ export async function userInformationFromDb(account: any) {
profile: profileResults[0],
}
}
export async function dbUserExists(username: string): Promise<boolean> {
const db = createSupabaseDirectClient()
const query = `SELECT 1 FROM users WHERE username = $1 LIMIT 1`
const result = await db.query(query, [username])
return result.length > 0
}

View File

@@ -73,3 +73,16 @@ export async function deleteAccount(idToken: any) {
throw err
}
}
/**
* Check if a Firebase user exists by email
* Returns userId if exists, undefined if not found
*/
export async function firebaseUserExists(email: string, password: string): Promise<string | undefined> {
try {
const login = await firebaseLoginEmailPassword(email, password)
return login.data.localId
} catch {
return undefined
}
}

View File

@@ -0,0 +1,44 @@
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)
await app.deleteProfileFromSettings()
const firebaseUserId = await firebaseUserExists(deleteAccount.email, deleteAccount.password)
expect(firebaseUserId).toBeUndefined()
const dbExists = await dbUserExists(deleteAccount.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')
const deleteAccount = testAccounts.faker_account()
await app.home.goToRegisterPage()
await app.auth.signInToGoogleAccount(
deleteAccount.email,
deleteAccount.display_name,
deleteAccount.username,
)
await app.skipOnboardingHeadToProfile(deleteAccount)
await app.deleteProfileFromSettings()
const dbExists = await dbUserExists(deleteAccount.username)
expect(dbExists).toBe(false)
})
})

View File

@@ -1,4 +1,3 @@
import {userInformationFromDb} from '../../utils/databaseUtils'
import {seedUser} from '../../utils/seedDatabase'
import {expect, test} from '../fixtures/signInFixture'
import {testAccounts} from '../utils/accountInformation'
@@ -25,51 +24,6 @@ test.describe('when given valid input', () => {
await app.home.goToHomePage()
await app.home.verifySignedInHomePage(dev_one_account.display_name)
})
test('should successfully delete an account created via email and password', async ({
app,
fakerAccount,
}) => {
await app.registerWithEmail(fakerAccount)
await app.skipOnboardingHeadToProfile(fakerAccount)
//Verify displayed information is correct
await app.profile.verifyDisplayName(fakerAccount.display_name)
//Verify database info
const dbInfo = await userInformationFromDb(fakerAccount)
await expect(dbInfo.user.name).toContain(fakerAccount.display_name)
await expect(dbInfo.user.username).toContain(fakerAccount.username)
await app.deleteProfileFromSettings()
})
test('should successfully delete an account created via google auth', async ({
app,
googleAccountTwo,
headless,
}) => {
test.skip(headless, 'Google popup auth test requires headed mode')
await app.home.goToRegisterPage()
await app.auth.signInToGoogleAccount(
googleAccountTwo.email,
googleAccountTwo.display_name,
googleAccountTwo.username,
)
await app.skipOnboardingHeadToProfile(googleAccountTwo)
//Verify displayed information is correct
await app.profile.verifyDisplayName(googleAccountTwo.display_name)
//Verify database info
const dbInfo = await userInformationFromDb(googleAccountTwo)
await expect(dbInfo.user.name).toContain(googleAccountTwo.display_name)
await expect(dbInfo.user.username).toContain(googleAccountTwo.username)
await app.deleteProfileFromSettings()
})
})
test.describe('when given invalid input', () => {