Add test for setting socket override and verify no errors are thrown on reload. Closes #2355

This commit is contained in:
Gabe Kangas 2022-12-08 18:37:01 -08:00
parent 3826f9380a
commit eb1fc9706f
No known key found for this signature in database
GPG Key ID: 4345B2060657F330

View File

@ -1,4 +1,5 @@
import { setup } from '../../support/setup.js';
setup();
describe(`Live tests`, () => {
@ -67,4 +68,58 @@ describe(`Live tests`, () => {
cy.wait(1500);
// cy.contains('is now known as').should('be.visible');
});
it('Should change to custom websocket host', () => {
fetchData('http://localhost:8080/api/admin/config/sockethostoverride', {
method: 'POST',
data: { value: 'ws://localhost:8080' },
});
cy.wait(1500);
});
it('Refresh page with new socket host', () => {
cy.visit('http://localhost:8080');
});
});
async function fetchData(url, options) {
const ADMIN_USERNAME = 'admin';
const ADMIN_STREAMKEY = 'abc123';
const { data, method = 'GET', auth = true } = options || {};
// eslint-disable-next-line no-undef
const requestOptions = {
method,
};
if (data) {
requestOptions.body = JSON.stringify(data);
}
if (auth && ADMIN_USERNAME && ADMIN_STREAMKEY) {
const encoded = btoa(`${ADMIN_USERNAME}:${ADMIN_STREAMKEY}`);
requestOptions.headers = {
Authorization: `Basic ${encoded}`,
};
requestOptions.mode = 'cors';
requestOptions.credentials = 'include';
}
try {
const response = await fetch(url, requestOptions);
const json = await response.json();
if (!response.ok) {
const message =
json.message || `An error has occurred: ${response.status}`;
throw new Error(message);
}
return json;
} catch (error) {
console.error(error);
return error;
// console.log(error)
// throw new Error(error)
}
}