family-binding.spec.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * ================================================================
  3. * Teacher Family Binding E2E Tests
  4. * ================================================================
  5. * Tests for teacher (成长规划师) family binding operations
  6. *
  7. * Seed data: teacher userId=1005 phone=13800000001, familyId=2001 bound
  8. * ================================================================
  9. */
  10. const { test, expect } = require('@playwright/test');
  11. const { loginAs, BASE_URL } = require('../../helpers/auth');
  12. const { assertApiSuccess, assertApiError, authHeaders } = require('../../helpers/utils');
  13. test.describe('【规划师】家庭绑定', () => {
  14. var auth;
  15. test.beforeAll(async ({ browser }) => {
  16. auth = await loginAs(browser, 'teacher');
  17. });
  18. test('[场景1] Generate bind invite link - expect invite token', async ({ page }) => {
  19. var headers = authHeaders(auth);
  20. // Create invite link for family binding
  21. var response = await page.request.post(BASE_URL + '/api/guide/invite/create', {
  22. data: {
  23. familyId: 2001
  24. },
  25. headers: headers
  26. });
  27. var data = await assertApiSuccess(response);
  28. // Verify invite token is returned
  29. if (!data || !data.inviteToken) {
  30. throw new Error('Expected inviteToken in response but got: ' + JSON.stringify(data));
  31. }
  32. console.log('Invite link created: inviteToken=' + data.inviteToken.substring(0, 20) + '...');
  33. });
  34. test('[场景1b] Create invite with invalid params - expect error', async ({ page }) => {
  35. var headers = authHeaders(auth);
  36. // Try to create invite with invalid familyId
  37. var response = await page.request.post(BASE_URL + '/api/guide/invite/create', {
  38. data: {
  39. familyId: -1
  40. },
  41. headers: headers
  42. });
  43. // Should return error
  44. await assertApiError(response);
  45. console.log('Invalid params correctly returned error');
  46. });
  47. test('[场景2] View bound family list - expect data', async ({ page }) => {
  48. var headers = authHeaders(auth);
  49. // Get list of bound families
  50. var response = await page.request.post(BASE_URL + '/api/guide/families/list', {
  51. data: {},
  52. headers: headers
  53. });
  54. var data = await assertApiSuccess(response);
  55. // Verify data is returned (array of families)
  56. if (!data || !Array.isArray(data)) {
  57. throw new Error('Expected array of families but got: ' + JSON.stringify(data));
  58. }
  59. // Verify at least one family is bound (familyId=2001 from seed data)
  60. if (data.length === 0) {
  61. throw new Error('Expected at least one bound family but got empty list');
  62. }
  63. console.log('Bound families list: ' + JSON.stringify(data));
  64. });
  65. test('[场景3] Unbind family - verify success', async ({ page }) => {
  66. var headers = authHeaders(auth);
  67. // First get the list to find a bindId or familyId to unbind
  68. var listResponse = await page.request.post(BASE_URL + '/api/guide/families/list', {
  69. data: {},
  70. headers: headers
  71. });
  72. var families = await assertApiSuccess(listResponse);
  73. if (!families || families.length === 0) {
  74. console.log('No families to unbind, skipping test');
  75. return;
  76. }
  77. // Get the first family's bindId or familyId
  78. var bindId = families[0].bindId || families[0].id || families[0].familyId;
  79. // Unbind the family
  80. var unbindResponse = await page.request.post(BASE_URL + '/api/guide/families/unbind', {
  81. data: {
  82. bindId: bindId
  83. },
  84. headers: headers
  85. });
  86. var unbindData = await assertApiSuccess(unbindResponse);
  87. console.log('Family unbound successfully: bindId=' + bindId);
  88. });
  89. });