Skip to content

Commit

Permalink
Playwright happy path case for skipping otp for existing phones
Browse files Browse the repository at this point in the history
  • Loading branch information
musidlo authored Nov 20, 2024
2 parents 780dac2 + f7bf7b0 commit 7df4997
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/playwright/tests/fixtures/auth/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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: {
Expand Down
5 changes: 3 additions & 2 deletions packages/playwright/tests/sign-in.anon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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')
Expand All @@ -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')
Expand Down
41 changes: 39 additions & 2 deletions packages/playwright/tests/sign-up.anon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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' })
Expand Down Expand 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({
Expand Down Expand Up @@ -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)
})
}
})
1 change: 1 addition & 0 deletions packages/playwright/tests/utils/generators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const generatePhone = () => `${Math.floor(Math.random() * 1e9)}`

0 comments on commit 7df4997

Please sign in to comment.