Skip to content

Commit 4dd22b4

Browse files
committed
Refactor account deletion E2E tests: extract to dedicated deleteAccount.spec.ts file
1 parent 46bad59 commit 4dd22b4

4 files changed

Lines changed: 64 additions & 46 deletions

File tree

‎tests/e2e/utils/databaseUtils.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ export async function userInformationFromDb(account: any) {
4646
profile: profileResults[0],
4747
}
4848
}
49+
50+
export async function dbUserExists(username: string): Promise<boolean> {
51+
const db = createSupabaseDirectClient()
52+
const query = `SELECT 1 FROM users WHERE username = $1 LIMIT 1`
53+
const result = await db.query(query, [username])
54+
return result.length > 0
55+
}

‎tests/e2e/utils/firebaseUtils.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,16 @@ export async function deleteAccount(idToken: any) {
7373
throw err
7474
}
7575
}
76+
77+
/**
78+
* Check if a Firebase user exists by email
79+
* Returns userId if exists, undefined if not found
80+
*/
81+
export async function firebaseUserExists(email: string, password: string): Promise<string | undefined> {
82+
try {
83+
const login = await firebaseLoginEmailPassword(email, password)
84+
return login.data.localId
85+
} catch {
86+
return undefined
87+
}
88+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {dbUserExists} from '../../utils/databaseUtils'
2+
import {firebaseUserExists} from '../../utils/firebaseUtils'
3+
import {seedUser} from '../../utils/seedDatabase'
4+
import {expect, test} from '../fixtures/signInFixture'
5+
import {testAccounts} from '../utils/accountInformation'
6+
7+
test.describe('delete account', () => {
8+
test('should successfully delete an account created via email and password', async ({app}) => {
9+
const deleteAccount = testAccounts.faker_account()
10+
await seedUser(
11+
deleteAccount.email,
12+
deleteAccount.password,
13+
undefined,
14+
deleteAccount.display_name,
15+
deleteAccount.username,
16+
)
17+
await app.signinWithEmail(deleteAccount)
18+
19+
await app.deleteProfileFromSettings()
20+
21+
const firebaseUserId = await firebaseUserExists(deleteAccount.email, deleteAccount.password)
22+
expect(firebaseUserId).toBeUndefined()
23+
24+
const dbExists = await dbUserExists(deleteAccount.username)
25+
expect(dbExists).toBe(false)
26+
})
27+
28+
test('should successfully delete an account created via google auth', async ({app, headless}) => {
29+
test.skip(headless, 'Google popup auth test requires headed mode')
30+
const deleteAccount = testAccounts.faker_account()
31+
await app.home.goToRegisterPage()
32+
await app.auth.signInToGoogleAccount(
33+
deleteAccount.email,
34+
deleteAccount.display_name,
35+
deleteAccount.username,
36+
)
37+
await app.skipOnboardingHeadToProfile(deleteAccount)
38+
39+
await app.deleteProfileFromSettings()
40+
41+
const dbExists = await dbUserExists(deleteAccount.username)
42+
expect(dbExists).toBe(false)
43+
})
44+
})

‎tests/e2e/web/specs/signIn.spec.ts‎

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {userInformationFromDb} from '../../utils/databaseUtils'
21
import {seedUser} from '../../utils/seedDatabase'
32
import {expect, test} from '../fixtures/signInFixture'
43
import {testAccounts} from '../utils/accountInformation'
@@ -25,51 +24,6 @@ test.describe('when given valid input', () => {
2524
await app.home.goToHomePage()
2625
await app.home.verifySignedInHomePage(dev_one_account.display_name)
2726
})
28-
29-
test('should successfully delete an account created via email and password', async ({
30-
app,
31-
fakerAccount,
32-
}) => {
33-
await app.registerWithEmail(fakerAccount)
34-
await app.skipOnboardingHeadToProfile(fakerAccount)
35-
36-
//Verify displayed information is correct
37-
await app.profile.verifyDisplayName(fakerAccount.display_name)
38-
39-
//Verify database info
40-
const dbInfo = await userInformationFromDb(fakerAccount)
41-
42-
await expect(dbInfo.user.name).toContain(fakerAccount.display_name)
43-
await expect(dbInfo.user.username).toContain(fakerAccount.username)
44-
45-
await app.deleteProfileFromSettings()
46-
})
47-
48-
test('should successfully delete an account created via google auth', async ({
49-
app,
50-
googleAccountTwo,
51-
headless,
52-
}) => {
53-
test.skip(headless, 'Google popup auth test requires headed mode')
54-
await app.home.goToRegisterPage()
55-
await app.auth.signInToGoogleAccount(
56-
googleAccountTwo.email,
57-
googleAccountTwo.display_name,
58-
googleAccountTwo.username,
59-
)
60-
await app.skipOnboardingHeadToProfile(googleAccountTwo)
61-
62-
//Verify displayed information is correct
63-
await app.profile.verifyDisplayName(googleAccountTwo.display_name)
64-
65-
//Verify database info
66-
const dbInfo = await userInformationFromDb(googleAccountTwo)
67-
68-
await expect(dbInfo.user.name).toContain(googleAccountTwo.display_name)
69-
await expect(dbInfo.user.username).toContain(googleAccountTwo.username)
70-
71-
await app.deleteProfileFromSettings()
72-
})
7327
})
7428

7529
test.describe('when given invalid input', () => {

0 commit comments

Comments
 (0)