Files
gold_land_user/e2e/market-rounding.spec.ts
T
safavimohadeseh78andCursor e3f0457dc9
Frontend CI / unit (test, type-check, build) (push) Successful in 1m11s
Frontend CI / browser E2E (frontend + pinned backend) (push) Failing after 2m48s
feat: complete server-backed six-lesson app and trial tooling
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-12 14:40:37 +03:30

68 lines
3.2 KiB
TypeScript

import { test, expect } from '@playwright/test'
import { tomansForGoldPurchase, tomansForGoldSale } from '../src/utils/goldTrade'
import { fetchMe, registerViaUi, uniqueUsername } from './helpers/auth'
test.describe('wallet rounding UI vs server', () => {
test('micro trade and standard buy/sell match server policy', async ({ page }) => {
const user = uniqueUsername('market')
await registerViaUi(page, user, 'pass1234')
const me0 = await fetchMe(page)
const cash0 = me0.wallet.cash
const gold0 = me0.wallet.goldGrams
await page.goto('/market')
await page.locator('button.trade-btn--buy').first().click()
const buyModal = page.getByRole('dialog')
await buyModal.locator('.trade-form__input').fill('0.000003')
await expect(page.getByText('برآورد هزینه (خرید به بالا)')).toBeVisible()
await buyModal.getByRole('button', { name: 'تأیید خرید' }).click()
await expect(page.getByText('خرید با موفقیت انجام شد!').last()).toBeVisible({ timeout: 15_000 })
await expect(buyModal).toBeHidden({ timeout: 10_000 })
let me = await fetchMe(page)
expect(me.wallet.goldGrams).toBeCloseTo(gold0 + 0.000_003, 6)
expect(me.wallet.cash).toBe(cash0 - tomansForGoldPurchase(0.000_003))
for (let i = 0; i < 3; i++) {
await page.locator('button.trade-btn--sell').first().click()
const sellModal = page.getByRole('dialog')
await sellModal.locator('.trade-form__input').fill('0.000001')
await sellModal.getByRole('button', { name: 'تأیید فروش' }).click()
await expect(page.getByText('فروش با موفقیت انجام شد!').last()).toBeVisible({
timeout: 15_000,
})
await expect(sellModal).toBeHidden({ timeout: 10_000 })
}
me = await fetchMe(page)
expect(me.wallet.goldGrams).toBeCloseTo(gold0, 6)
expect(me.wallet.cash).toBeLessThanOrEqual(cash0)
await page.locator('button.trade-btn--buy').first().click()
const buyModal2 = page.getByRole('dialog')
await buyModal2.locator('.trade-form__input').fill('0.05')
await expect(buyModal2.getByText('برآورد هزینه (خرید به بالا)')).toBeVisible()
await buyModal2.getByRole('button', { name: 'تأیید خرید' }).click()
await expect(page.getByText('خرید با موفقیت انجام شد!').last()).toBeVisible({ timeout: 15_000 })
me = await fetchMe(page)
expect(me.wallet.goldGrams).toBeGreaterThan(gold0 + 0.04)
})
test('invalid grams shows server error without changing balance', async ({ page }) => {
const user = uniqueUsername('marketbad')
await registerViaUi(page, user, 'pass1234')
const before = await fetchMe(page)
const snap = JSON.stringify(before.wallet)
await page.goto('/market')
await page.locator('button.trade-btn--buy').first().click()
await page.locator('.trade-form__input').fill('0.0000004')
await page.getByRole('button', { name: 'تأیید خرید' }).click()
await expect(page.getByText(/نامعتبر|کمتر از یک تومان|دقت/)).toBeVisible({ timeout: 15_000 })
const after = await fetchMe(page)
expect(JSON.stringify(after.wallet)).toBe(snap)
})
})