| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- /**
- * ================================================================
- * Teacher Family Binding E2E Tests
- * ================================================================
- * Tests for teacher (成长规划师) family binding operations
- *
- * Seed data: teacher userId=1005 phone=13800000001, familyId=2001 bound
- * ================================================================
- */
- const { test, expect } = require('@playwright/test');
- const { loginAs, BASE_URL } = require('../../helpers/auth');
- const { assertApiSuccess, assertApiError, authHeaders } = require('../../helpers/utils');
- test.describe('【规划师】家庭绑定', () => {
- var auth;
- test.beforeAll(async ({ browser }) => {
- auth = await loginAs(browser, 'teacher');
- });
- test('[场景1] Generate bind invite link - expect invite token', async ({ page }) => {
- var headers = 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 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('[场景1b] Create invite with invalid params - expect error', async ({ page }) => {
- var headers = 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 assertApiError(response);
- console.log('Invalid params correctly returned error');
- });
- test('[场景2] View bound family list - expect data', async ({ page }) => {
- var headers = 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 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');
- }
- console.log('Bound families list: ' + JSON.stringify(data));
- });
- test('[场景3] Unbind family - verify success', async ({ page }) => {
- var headers = 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 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 assertApiSuccess(unbindResponse);
- console.log('Family unbound successfully: bindId=' + bindId);
- });
- });
|