Skip to content

Commit f7bf7b0

Browse files
committed
Playwright case for skipping otp for existing phones
1 parent 780dac2 commit f7bf7b0

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

packages/playwright/tests/fixtures/auth/test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import jwt, { type JwtPayload } from 'jsonwebtoken'
1212
import config from '../../../playwright.config'
1313
import { assert } from 'app/utils/assert'
1414
import { faker } from '@faker-js/faker'
15+
import { generatePhone } from '../../utils/generators'
1516

1617
const randomCountry = () =>
1718
countries[Math.floor(Math.random() * countries.length)] as (typeof countries)[number]
@@ -105,7 +106,7 @@ const authTest = snapletTest.extend<{
105106
const { parallelIndex } = test.info()
106107
log = debug(`test:auth:${parallelIndex}`)
107108

108-
const randomNumber = Math.floor(Math.random() * 1e9)
109+
const randomNumber = generatePhone()
109110
const country = randomCountry()
110111
const { data, error } = await supabaseAdmin.auth.signUp({
111112
options: {

packages/playwright/tests/sign-in.anon.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { sendCoin } from 'app/data/coins'
66
import { assert } from 'app/utils/assert'
77
import debug from 'debug'
88
import { signUp } from './fixtures/send-accounts'
9+
import { generatePhone } from './utils/generators'
910

1011
let log: debug.Debugger
1112

@@ -16,7 +17,7 @@ test.beforeEach(async ({ page }) => {
1617
})
1718

1819
test('redirect on sign-in', async ({ page, pg }) => {
19-
const phone = `${Math.floor(Math.random() * 1e9)}`
20+
const phone = generatePhone()
2021
// naive but go to home page to see if user is logged in
2122
await page.goto('/auth/sign-up')
2223
await expect(page).toHaveURL('/auth/sign-up')
@@ -43,7 +44,7 @@ test('redirect on sign-in', async ({ page, pg }) => {
4344
})
4445

4546
test('redirect to send confirm page on sign-in', async ({ page, seed, pg }) => {
46-
const phone = `${Math.floor(Math.random() * 1e9)}`
47+
const phone = generatePhone()
4748
const plan = await seed.users([userOnboarded])
4849
const tag = plan.tags[0]
4950
assert(!!tag?.name, 'tag not found')

packages/playwright/tests/sign-up.anon.spec.ts

+39-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { countries } from 'app/utils/country'
55
import { SUPABASE_URL } from 'app/utils/supabase/admin'
66
import debug from 'debug'
77
import { signUp } from './fixtures/send-accounts'
8+
import { generatePhone } from './utils/generators'
89

910
let log: debug.Debugger
1011

@@ -18,7 +19,7 @@ const randomCountry = () =>
1819
countries[Math.floor(Math.random() * countries.length)] as (typeof countries)[number]
1920

2021
test('can sign up', async ({ page, pg }) => {
21-
const phone = `${Math.floor(Math.random() * 1e9)}`
22+
const phone = generatePhone()
2223
// naive but go to home page to see if user is logged in
2324
await page.goto('/')
2425
const signUpLink = page.getByRole('link', { name: 'SIGN-UP' })
@@ -50,7 +51,7 @@ test('can sign up', async ({ page, pg }) => {
5051

5152
test('country code is selected based on geoip', async ({ page, context, pg }) => {
5253
const country = randomCountry()
53-
const phone = `${Math.floor(Math.random() * 1e9)}`
54+
const phone = generatePhone()
5455

5556
await page.route('https://ipapi.co/json/', async (route) => {
5657
await route.fulfill({
@@ -81,3 +82,39 @@ test('country code is selected based on geoip', async ({ page, context, pg }) =>
8182
await pg.query('DELETE FROM auth.users WHERE phone = $1', [phone])
8283
}
8384
})
85+
86+
test('skip otp for existing user trying to sign up using already used phone number', async ({
87+
page,
88+
pg,
89+
}) => {
90+
const phone = generatePhone()
91+
await page.goto('/')
92+
93+
const signUpLink = page.getByRole('link', { name: 'SIGN-UP' })
94+
await expect(signUpLink).toBeVisible()
95+
await signUpLink.click()
96+
await expect(page).toHaveURL('/auth/sign-up')
97+
98+
try {
99+
await signUp(page, phone, expect)
100+
101+
await page.context().clearCookies()
102+
await page.goto('/')
103+
const signUpLink = page.getByRole('link', { name: 'SIGN-UP' })
104+
await expect(signUpLink).toBeVisible()
105+
await signUpLink.click()
106+
107+
await expect(page).toHaveURL('/auth/sign-up')
108+
await page.getByLabel('Phone number').fill(phone)
109+
const signUpButton = page.getByRole('button', { name: 'Sign Up' })
110+
await expect(signUpButton).toBeVisible()
111+
await signUpButton.click()
112+
113+
const depositButton = await page.getByRole('link', { name: 'Deposit' })
114+
await expect(depositButton).toBeVisible()
115+
} finally {
116+
await pg.query('DELETE FROM auth.users WHERE phone = $1', [phone]).catch((e) => {
117+
log('delete failed', e)
118+
})
119+
}
120+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const generatePhone = () => `${Math.floor(Math.random() * 1e9)}`

0 commit comments

Comments
 (0)