admin-commission-config.spec.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const { test, expect } = require('@playwright/test');
  2. function base() { return 'http' + String.fromCharCode(58, 47, 47) + 'cfc.iwintrue.com'; }
  3. function auth(token) { return token ? { Authorization: 'Bearer ' + token } : {}; }
  4. async function login(page) {
  5. const res = await page.request.post(base() + '/api/admin-auth/login-by-password', {
  6. data: { phone: '13800138000', password: 'admin123' }
  7. });
  8. return (await res.json()).data.token;
  9. }
  10. test.describe('commission config', () => {
  11. test('get config', async ({ page }) => {
  12. const t = await login(page);
  13. const res = await page.request.post(base() + '/api/admin/commission/config', { headers: auth(t) });
  14. expect(res.ok()).toBeTruthy();
  15. expect((await res.json()).code).toBe(200);
  16. });
  17. test('records', async ({ page }) => {
  18. const t = await login(page);
  19. const res = await page.request.post(base() + '/api/admin/commission/records', { headers: auth(t) });
  20. expect(res.ok()).toBeTruthy();
  21. expect((await res.json()).code).toBe(200);
  22. });
  23. test('update config', async ({ page }) => {
  24. const t = await login(page);
  25. // B-4/F2:实体字段为 name/rate/rateType/remark(rebate_commission_config 表 name NOT NULL)。
  26. // 旧 payload({percent,ratio,label,status}) 与实体不匹配 → name 缺失 → 插入违反非空约束返回 400。
  27. const res = await page.request.post(base() + '/api/admin/commission/config/update', {
  28. data: { id: null, name: 'e2e-' + Date.now(), rate: 10, rateType: 1, remark: 'up' },
  29. headers: auth(t)
  30. });
  31. expect(res.ok()).toBeTruthy();
  32. expect((await res.json()).code).toBe(200);
  33. });
  34. test('settle and refund', async ({ page }) => {
  35. const t = await login(page);
  36. const settle = await page.request.post(base() + '/api/admin/commission/settle', { data: {}, headers: auth(t) });
  37. expect(settle.ok()).toBeTruthy();
  38. expect((await settle.json()).code).toBe(200);
  39. const refund = await page.request.post(base() + '/api/admin/commission/refund', { data: {}, headers: auth(t) });
  40. expect(refund.ok()).toBeTruthy();
  41. expect((await refund.json()).code).toBe(200);
  42. });
  43. });