family-binding.spec.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. var BASE_URL = process.env.PW_BASE_URL || 'http://cfc.iwintrue.com';
  11. var test = require('../../../helpers/auth');
  12. var utils = require('../../../helpers/utils');
  13. test.describe('Teacher Family Binding Tests', function() {
  14. var auth;
  15. test.beforeAll(async function() {
  16. // Login as teacher before all tests
  17. auth = await test.loginAs(browser, 'teacher');
  18. });
  19. test('Scene 1: Generate bind invite link - expect invite token', async function() {
  20. var headers = utils.authHeaders(auth);
  21. // Create invite link for family binding
  22. var response = await page.request.post(BASE_URL + '/api/guide/invite/create', {
  23. data: {
  24. familyId: 2001
  25. },
  26. headers: headers
  27. });
  28. var data = await utils.assertApiSuccess(response);
  29. // Verify invite token is returned
  30. if (!data || !data.inviteToken) {
  31. throw new Error('Expected inviteToken in response but got: ' + JSON.stringify(data));
  32. }
  33. console.log('Invite link created: inviteToken=' + data.inviteToken.substring(0, 20) + '...');
  34. });
  35. test('Scene 1b: Create invite with invalid params - expect error', async function() {
  36. var headers = utils.authHeaders(auth);
  37. // Try to create invite with invalid familyId
  38. var response = await page.request.post(BASE_URL + '/api/guide/invite/create', {
  39. data: {
  40. familyId: -1
  41. },
  42. headers: headers
  43. });
  44. // Should return error
  45. await utils.assertApiError(response);
  46. console.log('Invalid params correctly returned error');
  47. });
  48. test('Scene 2: View bound family list - expect data', async function() {
  49. var headers = utils.authHeaders(auth);
  50. // Get list of bound families
  51. var response = await page.request.post(BASE_URL + '/api/guide/families/list', {
  52. data: {},
  53. headers: headers
  54. });
  55. var data = await utils.assertApiSuccess(response);
  56. // Verify data is returned (array of families)
  57. if (!data || !Array.isArray(data)) {
  58. throw new Error('Expected array of families but got: ' + JSON.stringify(data));
  59. }
  60. // Verify at least one family is bound (familyId=2001 from seed data)
  61. if (data.length === 0) {
  62. throw new Error('Expected at least one bound family but got empty list');
  63. }
  64. // Check if familyId 2001 is in the list
  65. var foundFamily2001 = false;
  66. for (var i = 0; i < data.length; i++) {
  67. if (data[i].familyId === 2001 || data[i].id === 2001) {
  68. foundFamily2001 = true;
  69. break;
  70. }
  71. }
  72. console.log('Bound families list: ' + JSON.stringify(data));
  73. console.log('Found family 2001: ' + foundFamily2001);
  74. });
  75. test('Scene 3: Unbind family - verify success', async function() {
  76. var headers = utils.authHeaders(auth);
  77. // First get the list to find a bindId or familyId to unbind
  78. var listResponse = await page.request.post(BASE_URL + '/api/guide/families/list', {
  79. data: {},
  80. headers: headers
  81. });
  82. var families = await utils.assertApiSuccess(listResponse);
  83. if (!families || families.length === 0) {
  84. console.log('No families to unbind, skipping test');
  85. return;
  86. }
  87. // Get the first family's bindId or familyId
  88. var bindId = families[0].bindId || families[0].id || families[0].familyId;
  89. // Unbind the family
  90. var unbindResponse = await page.request.post(BASE_URL + '/api/guide/families/unbind', {
  91. data: {
  92. bindId: bindId
  93. },
  94. headers: headers
  95. });
  96. var unbindData = await utils.assertApiSuccess(unbindResponse);
  97. console.log('Family unbound successfully: bindId=' + bindId);
  98. });
  99. });
  100. module.exports = {};