admin-activity-review.spec.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const { test, expect } = require('@playwright/test');
  2. function base() { return 'http' + String.fromCharCode(58, 47, 47) + 'cfc.iwintrue.com'; }
  3. function token(page) {
  4. return page.request.post(base() + '/api/admin-auth/login-by-password', {
  5. data: { phone: '13800138000', password: 'admin123' }
  6. }).then(r => r.ok() ? r.json() : Promise.resolve({ data: { token: null } })).then(j => j.data.token);
  7. }
  8. function auth(token) { return token ? { Authorization: 'Bearer ' + token } : {}; }
  9. test.describe('activity review', () => {
  10. test('login and list draft', async ({ page }) => {
  11. const res = await page.request.post(base() + '/api/admin-auth/login-by-password', {
  12. data: { phone: '13800138000', password: 'admin123' }
  13. });
  14. expect(res.ok()).toBeTruthy();
  15. const j = await res.json();
  16. expect(j.code).toBe(200);
  17. const t = j.data.token;
  18. expect(t).toBeTruthy();
  19. const list = await page.request.post(base() + '/api/admin/activity/list', {
  20. data: { status: 'draft', page: 1, size: 10 },
  21. headers: auth(t)
  22. });
  23. expect(list.ok()).toBeTruthy();
  24. const lj = await list.json();
  25. expect(lj.data).toHaveProperty('records');
  26. expect(lj.data).toHaveProperty('total');
  27. });
  28. test('review action', async ({ page }) => {
  29. const res = await page.request.post(base() + '/api/admin-auth/login-by-password', {
  30. data: { phone: '13800138000', password: 'admin123' }
  31. });
  32. const t = (await res.json()).data.token;
  33. const list = await page.request.post(base() + '/api/admin/activity/list', {
  34. data: { status: 'draft', page: 1, size: 1 },
  35. headers: auth(t)
  36. });
  37. const first = (await list.json()).data.records[0];
  38. if (!first) { expect(true).toBeTruthy(); return; }
  39. const rr = await page.request.post(base() + '/api/admin/activity/review', {
  40. data: { id: first.id, action: 'reject' },
  41. headers: auth(t)
  42. });
  43. expect(rr.ok()).toBeTruthy();
  44. expect((await rr.json()).code).toBe(200);
  45. });
  46. });