diff --git a/tests/e2e/utils/databaseUtils.ts b/tests/e2e/utils/databaseUtils.ts index 067613b6..daa95b22 100644 --- a/tests/e2e/utils/databaseUtils.ts +++ b/tests/e2e/utils/databaseUtils.ts @@ -46,3 +46,10 @@ export async function userInformationFromDb(account: any) { profile: profileResults[0], } } + +export async function dbUserExists(username: string): Promise { + 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 +} diff --git a/tests/e2e/utils/firebaseUtils.ts b/tests/e2e/utils/firebaseUtils.ts index a68d468c..96777d0b 100644 --- a/tests/e2e/utils/firebaseUtils.ts +++ b/tests/e2e/utils/firebaseUtils.ts @@ -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 { + try { + const login = await firebaseLoginEmailPassword(email, password) + return login.data.localId + } catch { + return undefined + } +} diff --git a/tests/e2e/web/specs/deleteAccount.spec.ts b/tests/e2e/web/specs/deleteAccount.spec.ts new file mode 100644 index 00000000..ffc1f5bb --- /dev/null +++ b/tests/e2e/web/specs/deleteAccount.spec.ts @@ -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) + }) +}) diff --git a/tests/e2e/web/specs/signIn.spec.ts b/tests/e2e/web/specs/signIn.spec.ts index 18c03712..5b52a29f 100644 --- a/tests/e2e/web/specs/signIn.spec.ts +++ b/tests/e2e/web/specs/signIn.spec.ts @@ -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', () => {