|
|
@@ -8,122 +8,48 @@
|
|
|
* ================================================================
|
|
|
*/
|
|
|
|
|
|
-var BASE_URL = process.env.PW_BASE_URL || 'http://cfc.iwintrue.com';
|
|
|
-
|
|
|
-var test = require('../../../helpers/auth');
|
|
|
-var utils = require('../../../helpers/utils');
|
|
|
+const { test, expect } = require('@playwright/test');
|
|
|
+const { loginAs, BASE_URL } = require('../../helpers/auth');
|
|
|
+const { assertApiSuccess, assertApiError, authHeaders } = require('../../helpers/utils');
|
|
|
|
|
|
test.describe('Teacher Family Binding Tests', function() {
|
|
|
var auth;
|
|
|
|
|
|
- test.beforeAll(async function() {
|
|
|
+ test.beforeAll(async function({ browser }) {
|
|
|
// Login as teacher before all tests
|
|
|
- auth = await test.loginAs(browser, 'teacher');
|
|
|
+ auth = await loginAs(browser, 'teacher');
|
|
|
});
|
|
|
|
|
|
- test('Scene 1: Generate bind invite link - expect invite token', async function() {
|
|
|
- var headers = utils.authHeaders(auth);
|
|
|
+ test('Scene 1: Generate parent invite link - expect invite data', async function({ page }) {
|
|
|
+ var headers = authHeaders(auth);
|
|
|
|
|
|
// Create invite link for family binding
|
|
|
- var response = await page.request.post(BASE_URL + '/api/guide/invite/create', {
|
|
|
+ var response = await page.request.post(BASE_URL + '/api/guide/parent-invite/generate', {
|
|
|
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);
|
|
|
+ var data = await assertApiSuccess(response);
|
|
|
|
|
|
- console.log('Invalid params correctly returned error');
|
|
|
+ // Verify invite data is returned
|
|
|
+ expect(data).toBeDefined();
|
|
|
+ expect(data.code || data.id).toBeDefined();
|
|
|
});
|
|
|
|
|
|
- test('Scene 2: View bound family list - expect data', async function() {
|
|
|
- var headers = utils.authHeaders(auth);
|
|
|
+ test('Scene 2: View bound family list - expect data', async function({ page }) {
|
|
|
+ var headers = authHeaders(auth);
|
|
|
|
|
|
// Get list of bound families
|
|
|
- var response = await page.request.post(BASE_URL + '/api/guide/families/list', {
|
|
|
+ var response = await page.request.post(BASE_URL + '/api/guide/family/list', {
|
|
|
data: {},
|
|
|
headers: headers
|
|
|
});
|
|
|
|
|
|
- var data = await utils.assertApiSuccess(response);
|
|
|
+ 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');
|
|
|
- }
|
|
|
-
|
|
|
- // 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);
|
|
|
+ expect(Array.isArray(data)).toBe(true);
|
|
|
});
|
|
|
-
|
|
|
- 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 = {};
|
|
|
+});
|