admin-butler-review.spec.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. expect(res.ok()).toBeTruthy();
  9. return (await res.json()).data.token;
  10. }
  11. test.describe('butler review', () => {
  12. test('list pending', async ({ page }) => {
  13. const t = await login(page);
  14. const res = await page.request.post(base() + '/api/admin/butler/list', {
  15. data: { status: 'pending', page: 1, size: 10 },
  16. headers: auth(t)
  17. });
  18. expect(res.ok()).toBeTruthy();
  19. const j = await res.json();
  20. expect(j.data).toHaveProperty('records');
  21. expect(j.data).toHaveProperty('total');
  22. });
  23. test('list approved for assignment', async ({ page }) => {
  24. const t = await login(page);
  25. const res = await page.request.post(base() + '/api/admin/butler/list', {
  26. data: { status: 'approved', page: 1, size: 10 },
  27. headers: auth(t)
  28. });
  29. expect(res.ok()).toBeTruthy();
  30. const j = await res.json();
  31. expect(j.data).toHaveProperty('records');
  32. expect(j.data).toHaveProperty('total');
  33. });
  34. test('review action (approve)', async ({ page }) => {
  35. const t = await login(page);
  36. const list = await page.request.post(base() + '/api/admin/butler/list', {
  37. data: { status: 'pending', page: 1, size: 1 },
  38. headers: auth(t)
  39. });
  40. const first = (await list.json()).data.records[0];
  41. if (!first) { expect(true).toBeTruthy(); return; }
  42. const res = await page.request.post(base() + '/api/admin/butler/review', {
  43. data: { id: first.id, action: 'approve' },
  44. headers: auth(t)
  45. });
  46. expect(res.ok()).toBeTruthy();
  47. expect((await res.json()).code).toBe(200);
  48. });
  49. test('assign member to approved butler', async ({ page }) => {
  50. const t = await login(page);
  51. const list = await page.request.post(base() + '/api/admin/butler/list', {
  52. data: { status: 'approved', page: 1, size: 1 },
  53. headers: auth(t)
  54. });
  55. const first = (await list.json()).data.records[0];
  56. if (!first) { expect(true).toBeTruthy(); return; }
  57. const res = await page.request.post(base() + '/api/admin/butler/assign-member', {
  58. data: { butlerId: first.id, memberIds: [] },
  59. headers: auth(t)
  60. });
  61. expect(res.ok()).toBeTruthy();
  62. expect((await res.json()).code).toBe(200);
  63. });
  64. test('service records exist', async ({ page }) => {
  65. const t = await login(page);
  66. const res = await page.request.post(base() + '/api/admin/butler/service-records', {
  67. data: { page: 1, size: 10 },
  68. headers: auth(t)
  69. });
  70. expect(res.ok()).toBeTruthy();
  71. expect((await res.json()).code).toBe(200);
  72. });
  73. test('settlements endpoint reachable', async ({ page }) => {
  74. const t = await login(page);
  75. const res = await page.request.post(base() + '/api/admin/butler/settlements', {
  76. data: { page: 1, size: 10 },
  77. headers: auth(t)
  78. });
  79. expect(res.ok()).toBeTruthy();
  80. expect((await res.json()).code).toBe(200);
  81. });
  82. });