diff --git a/packages/playwright/tests/fixtures/auth/test.ts b/packages/playwright/tests/fixtures/auth/test.ts index 9a83c7b51..5d96aa1ed 100644 --- a/packages/playwright/tests/fixtures/auth/test.ts +++ b/packages/playwright/tests/fixtures/auth/test.ts @@ -12,6 +12,7 @@ import jwt, { type JwtPayload } from 'jsonwebtoken' import config from '../../../playwright.config' import { assert } from 'app/utils/assert' import { faker } from '@faker-js/faker' +import { generatePhone } from '../../utils/generators' const randomCountry = () => countries[Math.floor(Math.random() * countries.length)] as (typeof countries)[number] @@ -105,7 +106,7 @@ const authTest = snapletTest.extend<{ const { parallelIndex } = test.info() log = debug(`test:auth:${parallelIndex}`) - const randomNumber = Math.floor(Math.random() * 1e9) + const randomNumber = generatePhone() const country = randomCountry() const { data, error } = await supabaseAdmin.auth.signUp({ options: { diff --git a/packages/playwright/tests/sign-in.anon.spec.ts b/packages/playwright/tests/sign-in.anon.spec.ts index 3d83ced4c..c19eb5d9f 100644 --- a/packages/playwright/tests/sign-in.anon.spec.ts +++ b/packages/playwright/tests/sign-in.anon.spec.ts @@ -6,6 +6,7 @@ import { sendCoin } from 'app/data/coins' import { assert } from 'app/utils/assert' import debug from 'debug' import { signUp } from './fixtures/send-accounts' +import { generatePhone } from './utils/generators' let log: debug.Debugger @@ -16,7 +17,7 @@ test.beforeEach(async ({ page }) => { }) test('redirect on sign-in', async ({ page, pg }) => { - const phone = `${Math.floor(Math.random() * 1e9)}` + const phone = generatePhone() // naive but go to home page to see if user is logged in await page.goto('/auth/sign-up') await expect(page).toHaveURL('/auth/sign-up') @@ -43,7 +44,7 @@ test('redirect on sign-in', async ({ page, pg }) => { }) test('redirect to send confirm page on sign-in', async ({ page, seed, pg }) => { - const phone = `${Math.floor(Math.random() * 1e9)}` + const phone = generatePhone() const plan = await seed.users([userOnboarded]) const tag = plan.tags[0] assert(!!tag?.name, 'tag not found') diff --git a/packages/playwright/tests/sign-up.anon.spec.ts b/packages/playwright/tests/sign-up.anon.spec.ts index b56660e1b..f46c7fd1b 100644 --- a/packages/playwright/tests/sign-up.anon.spec.ts +++ b/packages/playwright/tests/sign-up.anon.spec.ts @@ -5,6 +5,7 @@ import { countries } from 'app/utils/country' import { SUPABASE_URL } from 'app/utils/supabase/admin' import debug from 'debug' import { signUp } from './fixtures/send-accounts' +import { generatePhone } from './utils/generators' let log: debug.Debugger @@ -18,7 +19,7 @@ const randomCountry = () => countries[Math.floor(Math.random() * countries.length)] as (typeof countries)[number] test('can sign up', async ({ page, pg }) => { - const phone = `${Math.floor(Math.random() * 1e9)}` + const phone = generatePhone() // naive but go to home page to see if user is logged in await page.goto('/') const signUpLink = page.getByRole('link', { name: 'SIGN-UP' }) @@ -50,7 +51,7 @@ test('can sign up', async ({ page, pg }) => { test('country code is selected based on geoip', async ({ page, context, pg }) => { const country = randomCountry() - const phone = `${Math.floor(Math.random() * 1e9)}` + const phone = generatePhone() await page.route('https://ipapi.co/json/', async (route) => { await route.fulfill({ @@ -81,3 +82,39 @@ test('country code is selected based on geoip', async ({ page, context, pg }) => await pg.query('DELETE FROM auth.users WHERE phone = $1', [phone]) } }) + +test('skip otp for existing user trying to sign up using already used phone number', async ({ + page, + pg, +}) => { + const phone = generatePhone() + await page.goto('/') + + const signUpLink = page.getByRole('link', { name: 'SIGN-UP' }) + await expect(signUpLink).toBeVisible() + await signUpLink.click() + await expect(page).toHaveURL('/auth/sign-up') + + try { + await signUp(page, phone, expect) + + await page.context().clearCookies() + await page.goto('/') + const signUpLink = page.getByRole('link', { name: 'SIGN-UP' }) + await expect(signUpLink).toBeVisible() + await signUpLink.click() + + await expect(page).toHaveURL('/auth/sign-up') + await page.getByLabel('Phone number').fill(phone) + const signUpButton = page.getByRole('button', { name: 'Sign Up' }) + await expect(signUpButton).toBeVisible() + await signUpButton.click() + + const depositButton = await page.getByRole('link', { name: 'Deposit' }) + await expect(depositButton).toBeVisible() + } finally { + await pg.query('DELETE FROM auth.users WHERE phone = $1', [phone]).catch((e) => { + log('delete failed', e) + }) + } +}) diff --git a/packages/playwright/tests/utils/generators.ts b/packages/playwright/tests/utils/generators.ts new file mode 100644 index 000000000..02da1522d --- /dev/null +++ b/packages/playwright/tests/utils/generators.ts @@ -0,0 +1 @@ +export const generatePhone = () => `${Math.floor(Math.random() * 1e9)}`