var request = require('supertest');
request = request('http://127.0.0.1:8080');
var accessToken = '';
var webhookID;
const webhook = 'https://super.duper.cool.thing.biz/owncast';
const events = ['CHAT'];
test('create webhook', async (done) => {
const res = await sendIntegrationsChangePayload('webhooks/create', {
url: webhook,
events: events,
});
expect(res.body.url).toBe(webhook);
expect(res.body.timestamp).toBeTruthy();
expect(res.body.events).toStrictEqual(events);
done();
test('check webhooks', (done) => {
request.get('/api/admin/webhooks')
.auth('admin', 'abc123').expect(200)
.then((res) => {
expect(res.body).toHaveLength(1);
expect(res.body[0].url).toBe(webhook);
expect(res.body[0].events).toStrictEqual(events);
webhookID = res.body[0].id;
test('delete webhook', async (done) => {
const res = await sendIntegrationsChangePayload('webhooks/delete', {
id: webhookID,
expect(res.body.success).toBe(true);
test('check that webhook was deleted', (done) => {
expect(res.body).toHaveLength(0);
test('create access token', async (done) => {
const name = 'Automated integration test';
const scopes = ['CAN_SEND_SYSTEM_MESSAGES', 'CAN_SEND_MESSAGES'];
const res = await sendIntegrationsChangePayload('accesstokens/create', {
name: name,
scopes: scopes,
expect(res.body.accessToken).toBeTruthy();
expect(res.body.createdAt).toBeTruthy();
expect(res.body.displayName).toBe(name);
expect(res.body.scopes).toStrictEqual(scopes);
accessToken = res.body.accessToken;
test('check access tokens', async (done) => {
const res = await request.get('/api/admin/accesstokens')
const tokenCheck = res.body.filter((token) => token.accessToken === accessToken)
expect(tokenCheck).toHaveLength(1);
test('send a system message using access token', async (done) => {
const payload = {body: 'This is a test system message from the automated integration test'};
const res = await request.post('/api/integrations/chat/system')
.set('Authorization', 'Bearer ' + accessToken)
.send(payload).expect(200);
test('send an external integration message using access token', async (done) => {
const payload = {body: 'This is a test external message from the automated integration test'};
const res = await request.post('/api/integrations/chat/send')
test('send an external integration action using access token', async (done) => {
const payload = {body: 'This is a test external action from the automated integration test'};
const res = await request.post('/api/integrations/chat/action')
test('delete access token', async (done) => {
const res = await sendIntegrationsChangePayload('accesstokens/delete', {
token: accessToken,
test('check token delete was successful', async (done) => {
expect(tokenCheck).toHaveLength(0);
async function sendIntegrationsChangePayload(endpoint, payload) {
const url = '/api/admin/' + endpoint;
const res = await request.post(url)
.auth('admin', 'abc123')
return res
}