feat: complete server-backed six-lesson app and trial tooling
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
export function uniqueUsername(prefix = 'e2e'): string {
|
||||
return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`
|
||||
}
|
||||
|
||||
export async function registerViaUi(
|
||||
page: Page,
|
||||
username: string,
|
||||
password: string,
|
||||
displayName?: string,
|
||||
) {
|
||||
await page.goto('/login')
|
||||
await page.getByRole('button', { name: 'ثبتنام کن' }).click()
|
||||
if (displayName) {
|
||||
await page.getByLabel('نام نمایشی').fill(displayName)
|
||||
}
|
||||
await page.getByLabel('نام کاربری').fill(username)
|
||||
await page.getByLabel('رمز عبور').fill(password)
|
||||
await page.getByRole('button', { name: 'ثبتنام' }).click()
|
||||
await page.waitForURL('/')
|
||||
}
|
||||
|
||||
export async function loginViaUi(page: Page, username: string, password: string) {
|
||||
await page.goto('/login')
|
||||
await page.getByLabel('نام کاربری').fill(username)
|
||||
await page.getByLabel('رمز عبور').fill(password)
|
||||
await page.getByRole('button', { name: 'ورود', exact: true }).click()
|
||||
await page.waitForURL('/')
|
||||
}
|
||||
|
||||
export async function logoutViaProfile(page: Page) {
|
||||
await page.goto('/profile')
|
||||
await page.getByRole('button', { name: 'خروج' }).click()
|
||||
await page.waitForURL('/login')
|
||||
}
|
||||
|
||||
export async function getAuthToken(page: Page): Promise<string | null> {
|
||||
return page.evaluate(() => localStorage.getItem('gold-land-auth-token'))
|
||||
}
|
||||
|
||||
export async function fetchMe(page: Page) {
|
||||
const token = await getAuthToken(page)
|
||||
if (!token) throw new Error('no auth token')
|
||||
const res = await page.request.get('/api/me', {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (!res.ok()) throw new Error(`GET /api/me failed: ${res.status()}`)
|
||||
return res.json() as Promise<{
|
||||
user: { xp: number; coins: number; name: string }
|
||||
progress: {
|
||||
mapLevels: Array<{ id: number; stars: number; status: string }>
|
||||
totalStars: number
|
||||
completedChallenges: string[]
|
||||
claimedRewards: string[]
|
||||
ownedItems: string[]
|
||||
}
|
||||
wallet: { cash: number; goldGrams: number }
|
||||
}>
|
||||
}
|
||||
Reference in New Issue
Block a user