admin-commission-config.spec.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. const res = await page.request.post(base() + '/api/admin/commission/config/update', {
  26. data: { id: null, percent: 10, ratio: 1, label: 'e2e-' + Date.now(), status: 1, remark: 'up' },
  27. headers: auth(t)
  28. });
  29. expect(res.ok()).toBeTruthy();
  30. expect((await res.json()).code).toBe(200);
  31. });
  32. test('settle and refund', async ({ page }) => {
  33. const t = await login(page);
  34. const settle = await page.request.post(base() + '/api/admin/commission/settle', { data: {}, headers: auth(t) });
  35. expect(settle.ok()).toBeTruthy();
  36. expect((await settle.json()).code).toBe(200);
  37. const refund = await page.request.post(base() + '/api/admin/commission/refund', { data: {}, headers: auth(t) });
  38. expect(refund.ok()).toBeTruthy();
  39. expect((await refund.json()).code).toBe(200);
  40. });
  41. });