2021-11-03 00:45:52 +08:00
|
|
|
require('dotenv').config();
|
|
|
|
const sha1 = require('sha1');
|
|
|
|
const axios = require('axios');
|
2022-12-01 21:43:36 +08:00
|
|
|
const { test } = require('@playwright/test');
|
2022-09-06 11:45:53 +08:00
|
|
|
const xml2js = require('xml2js');
|
|
|
|
|
2022-11-08 05:59:16 +08:00
|
|
|
const { expect } = require("@playwright/test");
|
|
|
|
|
2022-09-06 11:45:53 +08:00
|
|
|
const parameters = require('./parameters');
|
2021-11-03 00:45:52 +08:00
|
|
|
|
|
|
|
function getRandomInt(min, max) {
|
|
|
|
min = Math.ceil(min);
|
|
|
|
max = Math.floor(max);
|
|
|
|
return Math.floor(Math.random() * (max - min)) + min;
|
|
|
|
}
|
|
|
|
|
2022-10-10 03:10:05 +08:00
|
|
|
function apiCallUrl(name, callParams) {
|
2022-09-06 11:45:53 +08:00
|
|
|
const query = new URLSearchParams(callParams).toString();
|
|
|
|
const apicall = `${name}${query}${parameters.secret}`;
|
|
|
|
const checksum = sha1(apicall);
|
|
|
|
const url = `${parameters.server}/${name}?${query}&checksum=${checksum}`;
|
2022-10-10 03:10:05 +08:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
function apiCall(name, callParams) {
|
|
|
|
const url = apiCallUrl(name, callParams);
|
2022-12-15 02:51:26 +08:00
|
|
|
return axios.get(url, { adapter: 'http' }).then(response => xml2js.parseStringPromise(response.data));
|
2022-09-06 11:45:53 +08:00
|
|
|
}
|
|
|
|
|
2022-10-10 03:10:05 +08:00
|
|
|
function createMeetingUrl(params, customParameter) {
|
2021-11-19 04:09:29 +08:00
|
|
|
const meetingID = `random-${getRandomInt(1000000, 10000000).toString()}`;
|
2021-11-03 00:45:52 +08:00
|
|
|
const mp = params.moderatorPW;
|
|
|
|
const ap = params.attendeePW;
|
2022-06-21 23:38:53 +08:00
|
|
|
const query = customParameter !== undefined ? `name=${meetingID}&meetingID=${meetingID}&attendeePW=${ap}&moderatorPW=${mp}`
|
2021-12-15 01:10:44 +08:00
|
|
|
+ `&allowStartStopRecording=true&${customParameter}&autoStartRecording=false&welcome=${params.welcome}`
|
2022-06-21 23:38:53 +08:00
|
|
|
: `name=${meetingID}&meetingID=${meetingID}&attendeePW=${ap}&moderatorPW=${mp}`
|
2021-12-15 01:10:44 +08:00
|
|
|
+ `&allowStartStopRecording=true&autoStartRecording=false&welcome=${params.welcome}`;
|
2021-11-03 00:45:52 +08:00
|
|
|
const apicall = `create${query}${params.secret}`;
|
|
|
|
const checksum = sha1(apicall);
|
|
|
|
const url = `${params.server}/create?${query}&checksum=${checksum}`;
|
2022-10-10 03:10:05 +08:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createMeetingPromise(params, customParameter) {
|
|
|
|
const url = createMeetingUrl(params, customParameter);
|
2022-12-15 02:51:26 +08:00
|
|
|
return axios.get(url, { adapter: 'http' });
|
2022-10-10 03:10:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async function createMeeting(params, customParameter) {
|
|
|
|
const promise = createMeetingPromise(params, customParameter);
|
2022-11-08 05:59:16 +08:00
|
|
|
const response = await promise;
|
2022-11-08 07:22:14 +08:00
|
|
|
expect(response.status).toEqual(200);
|
2022-11-08 05:59:16 +08:00
|
|
|
const xmlresponse = await xml2js.parseStringPromise(response.data);
|
|
|
|
return xmlresponse.response.meetingID[0];
|
2021-11-03 00:45:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function getJoinURL(meetingID, params, moderator, customParameter) {
|
|
|
|
const pw = moderator ? params.moderatorPW : params.attendeePW;
|
2022-06-21 23:38:53 +08:00
|
|
|
const query = customParameter !== undefined ? `fullName=${params.fullName}&meetingID=${meetingID}&password=${pw}&${customParameter}`
|
|
|
|
: `fullName=${params.fullName}&meetingID=${meetingID}&password=${pw}`;
|
2021-11-03 00:45:52 +08:00
|
|
|
const apicall = `join${query}${params.secret}`;
|
|
|
|
const checksum = sha1(apicall);
|
|
|
|
return `${params.server}/join?${query}&checksum=${checksum}`;
|
|
|
|
}
|
|
|
|
|
2022-12-01 21:43:36 +08:00
|
|
|
function linkIssue(issueNumber) {
|
|
|
|
test.info().annotations.push({
|
|
|
|
type: 'Issue/PR',
|
|
|
|
description: `https://github.com/bigbluebutton/bigbluebutton/issues/${issueNumber}`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-27 04:01:41 +08:00
|
|
|
function sleep(time) {
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
setTimeout(resolve, time);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-03 00:45:52 +08:00
|
|
|
exports.getRandomInt = getRandomInt;
|
2022-10-10 03:10:05 +08:00
|
|
|
exports.apiCallUrl = apiCallUrl;
|
2022-09-06 11:45:53 +08:00
|
|
|
exports.apiCall = apiCall;
|
2022-10-10 03:10:05 +08:00
|
|
|
exports.createMeetingUrl = createMeetingUrl;
|
|
|
|
exports.createMeetingPromise = createMeetingPromise;
|
2021-11-03 00:45:52 +08:00
|
|
|
exports.createMeeting = createMeeting;
|
|
|
|
exports.getJoinURL = getJoinURL;
|
2022-12-01 21:43:36 +08:00
|
|
|
exports.linkIssue = linkIssue;
|
2021-11-27 04:01:41 +08:00
|
|
|
exports.sleep = sleep;
|