Files
lotteryLaravel/e2e/tests/api/14.settlement-payment.spec.ts
kang 6ec9634704
Some checks failed
lotterLaravel CI / test (push) Has been cancelled
feat: 添加E2E测试环境配置支持
添加LOTTERY_E2E环境变量来控制E2E测试相关功能,
包括绕过验证码、登录限制和钱包API URL验证,
同时更新composer.json以包含E2E专用的提供者和服务。
2026-06-18 14:42:22 +08:00

109 lines
3.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* E2E代理账期关账 → confirm → 登记收付 → 账单 settled。
*/
import { test, expect } from '@playwright/test';
import {
adminLoginViaBypass,
adminCtxOf,
fetchOpenDrawNo,
playerLoginViaBypass,
setupCreditPlayer,
} from './_helper';
import { runWalletDrawSettlement } from './helpers/draw-settlement';
test('关账后 confirm + 全额收付 → 玩家账单 settled + payment_records', async () => {
test.setTimeout(300_000);
const credit = await setupCreditPlayer({
credit_limit: 100_000,
username: `e2e_pay_${Date.now()}`,
});
const drawNo = await fetchOpenDrawNo();
const winNumber = `8${String(Date.now()).slice(-3)}`;
const adminSession = await adminLoginViaBypass();
const admin = await adminCtxOf(adminSession.accessToken);
const start = new Date(Date.now() - 3600_000).toISOString().replace('T', ' ').slice(0, 19);
const end = new Date(Date.now() + 3600_000).toISOString().replace('T', ' ').slice(0, 19);
const open = await admin.post('/api/v1/admin/settlement-periods', {
data: {
admin_site_id: credit.admin_site_id,
period_start: start,
period_end: end,
},
});
expect(open.ok(), `open period status=${open.status()}`).toBeTruthy();
const openBody = (await open.json()) as any;
expect(openBody.code).toBe(0);
const periodId = openBody.data.id;
const playerSession = await playerLoginViaBypass({
site_code: credit.site_code,
username: credit.username,
password: credit.password,
});
await runWalletDrawSettlement({
adminToken: adminSession.accessToken,
playerToken: playerSession.access_token,
drawNo,
betNumber: winNumber,
betAmount: 10_000,
expectWalletIncrease: false,
});
const close = await admin.post(`/api/v1/admin/settlement-periods/${periodId}/close`);
expect(close.ok(), `close period status=${close.status()}`).toBeTruthy();
const closeBody = (await close.json()) as any;
expect(closeBody.code).toBe(0);
const bills = await admin.get(
`/api/v1/admin/settlement-bills?settlement_period_id=${periodId}&size=20`,
);
const billsBody = (await bills.json()) as any;
expect(billsBody.code).toBe(0);
const playerBill = billsBody.data.items.find(
(b: any) => b.bill_type === 'player' && Number(b.owner_id) === credit.player_id,
);
expect(playerBill, '应有该信用玩家的账单').toBeTruthy();
expect(playerBill.status).toBe('pending_confirm');
const unpaid = Number(playerBill.unpaid_amount);
expect(unpaid).toBeGreaterThan(0);
const confirm = await admin.post(`/api/v1/admin/settlement-bills/${playerBill.id}/confirm`);
expect(confirm.ok(), `confirm status=${confirm.status()}`).toBeTruthy();
const confirmBody = (await confirm.json()) as any;
expect(confirmBody.code).toBe(0);
expect(confirmBody.data.status).toBe('confirmed');
const pay = await admin.post(`/api/v1/admin/settlement-bills/${playerBill.id}/payments`, {
data: {
amount: unpaid,
method: 'e2e_cash',
remark: 'e2e full payment',
},
});
expect(pay.ok(), `payment status=${pay.status()}`).toBeTruthy();
const payBody = (await pay.json()) as any;
expect(payBody.code).toBe(0);
expect(payBody.data.bill.status).toBe('settled');
expect(Number(payBody.data.bill.paid_amount)).toBe(unpaid);
expect(Number(payBody.data.bill.unpaid_amount)).toBe(0);
const payments = await admin.get(
`/api/v1/admin/settlement-payments?settlement_period_id=${periodId}&size=20`,
);
const paymentsBody = (await payments.json()) as any;
expect(paymentsBody.code).toBe(0);
const recorded = paymentsBody.data.items.find(
(p: any) => Number(p.settlement_bill_id) === Number(playerBill.id),
);
expect(recorded, '收付台账应有该账单记录').toBeTruthy();
expect(Number(recorded.amount)).toBe(unpaid);
await admin.dispose();
});