wish-management.spec.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const { test, expect } = require('@playwright/test');
  2. const { loginAs, BASE_URL } = require('../../helpers/auth');
  3. const { assertApiSuccess, assertApiError, authHeaders } = require('../../helpers/utils');
  4. test.describe('【家长】心愿管理', () => {
  5. var auth;
  6. test.beforeAll(async ({ browser }) => {
  7. auth = await loginAs(browser, 'parent');
  8. });
  9. test('[场景1] 查看孩子心愿列表 — 期望返回心愿数据', async ({ page }) => {
  10. var resp = await page.request.post(BASE_URL + '/api/wishes/list?childId=1003&familyId=2001', {
  11. headers: authHeaders(auth),
  12. data: {}
  13. });
  14. var data = await assertApiSuccess(resp);
  15. expect(data).toBeDefined();
  16. });
  17. test('[场景2] 查看待处理心愿列表 — 期望返回待处理数据', async ({ page }) => {
  18. var resp = await page.request.post(BASE_URL + '/api/wishes/pending', {
  19. headers: authHeaders(auth),
  20. data: {
  21. familyId: 2001
  22. }
  23. });
  24. var data = await assertApiSuccess(resp);
  25. expect(data).toBeDefined();
  26. });
  27. // Scene 3 & 4 both verify the wish detail endpoint handles missing data correctly
  28. test('[场景3] 查看不存在的心愿详情 — 期望返回业务错误', async ({ page }) => {
  29. var resp = await page.request.post(BASE_URL + '/api/wishes/999999', {
  30. headers: authHeaders(auth),
  31. data: {}
  32. });
  33. await assertApiError(resp);
  34. });
  35. test('[场景4] 另一无效ID的心愿详情 — 同样期望返回业务错误', async ({ page }) => {
  36. var resp = await page.request.post(BASE_URL + '/api/wishes/1', {
  37. headers: authHeaders(auth),
  38. data: {}
  39. });
  40. await assertApiError(resp);
  41. });
  42. });