admin-ecom-supplier.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 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('ecom supplier', () => {
  11. test('list pagination schema', async ({ page }) => {
  12. const t = await login(page);
  13. const res = await page.request.post(base() + '/api/admin/supplier/list', {
  14. data: { page: 1, size: 5 },
  15. headers: auth(t)
  16. });
  17. expect(res.ok()).toBeTruthy();
  18. const j = await res.json();
  19. expect(j.data).toHaveProperty('records');
  20. expect(j.data).toHaveProperty('total');
  21. });
  22. test('create supplier', async ({ page }) => {
  23. const t = await login(page);
  24. const res = await page.request.post(base() + '/api/admin/supplier/save', {
  25. data: { name: 'PlaywrightSupplier ' + Date.now(), contactName: 'Sisy', contactPhone: '74955953457', status: 1, remark: 'e2e' },
  26. headers: auth(t)
  27. });
  28. expect(res.ok()).toBeTruthy();
  29. expect((await res.json()).code).toBe(200);
  30. });
  31. test('update supplier', async ({ page }) => {
  32. const t = await login(page);
  33. const list = await page.request.post(base() + '/api/admin/supplier/list', {
  34. data: { 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 res = await page.request.post(base() + '/api/admin/supplier/update', {
  40. data: { id: first.id, remark: 'updated ' + Date.now() },
  41. headers: auth(t)
  42. });
  43. expect(res.ok()).toBeTruthy();
  44. expect((await res.json()).code).toBe(200);
  45. });
  46. });