daily-checkin.spec.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const { test, expect } = require('@playwright/test');
  2. const { loginAs, BASE_URL } = require('../../helpers/auth');
  3. const { assertApiSuccess, authHeaders } = require('../../helpers/utils');
  4. test.describe('【孩子】健康打卡', function() {
  5. var auth;
  6. test.beforeAll(async function({ browser }) {
  7. auth = await loginAs(browser, 'child');
  8. });
  9. test('[场景1] 完成每日打卡 — 打卡成功', async function({ page }) {
  10. var resp = await page.request.post(BASE_URL + '/api/health/checkin/create', {
  11. headers: authHeaders(auth),
  12. data: { childId: 1003, dietScore: 85, exerciseScore: 70, sleepScore: 90, moodScore: 80 },
  13. });
  14. await assertApiSuccess(resp);
  15. });
  16. test('[场景1b] 打卡数据为空 — 期望错误', async function({ page }) {
  17. var resp = await page.request.post(BASE_URL + '/api/health/checkin/create', {
  18. headers: authHeaders(auth),
  19. data: {},
  20. });
  21. var body = await resp.json();
  22. expect(body.code).not.toBe(200);
  23. });
  24. test('[场景2] 查看连续签到 — 返回天数', async function({ page }) {
  25. var resp = await page.request.post(BASE_URL + '/api/health/checkin/streak', {
  26. headers: authHeaders(auth),
  27. data: { childId: 1003 },
  28. });
  29. var data = await assertApiSuccess(resp);
  30. expect(data).toBeTruthy();
  31. });
  32. });