| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- /**
- * ================================================================
- * Teacher Family Binding E2E Tests
- * ================================================================
- * Tests for teacher (成长规划师) family binding operations
- *
- * Seed data: teacher userId=1005 phone=13800000001, familyId=2001 bound
- * ================================================================
- */
- var BASE_URL = process.env.PW_BASE_URL || 'http://cfc.iwintrue.com';
- var test = require('../../../helpers/auth');
- var utils = require('../../../helpers/utils');
- test.describe('Teacher Family Binding Tests', function() {
- var auth;
- test.beforeAll(async function() {
- // Login as teacher before all tests
- auth = await test.loginAs(browser, 'teacher');
- });
- test('Scene 1: Generate bind invite link - expect invite token', async function() {
- var headers = utils.authHeaders(auth);
- // Create invite link for family binding
- var response = await page.request.post(BASE_URL + '/api/guide/invite/create', {
- data: {
- familyId: 2001
- },
- headers: headers
- });
- var data = await utils.assertApiSuccess(response);
- // Verify invite token is returned
- if (!data || !data.inviteToken) {
- throw new Error('Expected inviteToken in response but got: ' + JSON.stringify(data));
- }
- console.log('Invite link created: inviteToken=' + data.inviteToken.substring(0, 20) + '...');
- });
- test('Scene 1b: Create invite with invalid params - expect error', async function() {
- var headers = utils.authHeaders(auth);
- // Try to create invite with invalid familyId
- var response = await page.request.post(BASE_URL + '/api/guide/invite/create', {
- data: {
- familyId: -1
- },
- headers: headers
- });
- // Should return error
- await utils.assertApiError(response);
- console.log('Invalid params correctly returned error');
- });
- test('Scene 2: View bound family list - expect data', async function() {
- var headers = utils.authHeaders(auth);
- // Get list of bound families
- var response = await page.request.post(BASE_URL + '/api/guide/families/list', {
- data: {},
- headers: headers
- });
- var data = await utils.assertApiSuccess(response);
- // Verify data is returned (array of families)
- if (!data || !Array.isArray(data)) {
- throw new Error('Expected array of families but got: ' + JSON.stringify(data));
- }
- // Verify at least one family is bound (familyId=2001 from seed data)
- if (data.length === 0) {
- throw new Error('Expected at least one bound family but got empty list');
- }
- // Check if familyId 2001 is in the list
- var foundFamily2001 = false;
- for (var i = 0; i < data.length; i++) {
- if (data[i].familyId === 2001 || data[i].id === 2001) {
- foundFamily2001 = true;
- break;
- }
- }
- console.log('Bound families list: ' + JSON.stringify(data));
- console.log('Found family 2001: ' + foundFamily2001);
- });
- test('Scene 3: Unbind family - verify success', async function() {
- var headers = utils.authHeaders(auth);
- // First get the list to find a bindId or familyId to unbind
- var listResponse = await page.request.post(BASE_URL + '/api/guide/families/list', {
- data: {},
- headers: headers
- });
- var families = await utils.assertApiSuccess(listResponse);
- if (!families || families.length === 0) {
- console.log('No families to unbind, skipping test');
- return;
- }
- // Get the first family's bindId or familyId
- var bindId = families[0].bindId || families[0].id || families[0].familyId;
- // Unbind the family
- var unbindResponse = await page.request.post(BASE_URL + '/api/guide/families/unbind', {
- data: {
- bindId: bindId
- },
- headers: headers
- });
- var unbindData = await utils.assertApiSuccess(unbindResponse);
- console.log('Family unbound successfully: bindId=' + bindId);
- });
- });
- module.exports = {};
|