2021-02-19 10:05:52 +03:00
|
|
|
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,
|
2021-07-28 22:37:41 +03:00
|
|
|
events: events,
|
2021-02-19 10:05:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.body.url).toBe(webhook);
|
|
|
|
expect(res.body.timestamp).toBeTruthy();
|
|
|
|
expect(res.body.events).toStrictEqual(events);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('check webhooks', (done) => {
|
2021-07-28 22:37:41 +03:00
|
|
|
request
|
|
|
|
.get('/api/admin/webhooks')
|
|
|
|
.auth('admin', 'abc123')
|
|
|
|
.expect(200)
|
2021-02-19 10:05:52 +03:00
|
|
|
.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;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('delete webhook', async (done) => {
|
|
|
|
const res = await sendIntegrationsChangePayload('webhooks/delete', {
|
|
|
|
id: webhookID,
|
|
|
|
});
|
|
|
|
expect(res.body.success).toBe(true);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('check that webhook was deleted', (done) => {
|
2021-07-28 22:37:41 +03:00
|
|
|
request
|
|
|
|
.get('/api/admin/webhooks')
|
|
|
|
.auth('admin', 'abc123')
|
|
|
|
.expect(200)
|
2021-02-19 10:05:52 +03:00
|
|
|
.then((res) => {
|
|
|
|
expect(res.body).toHaveLength(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('create access token', async (done) => {
|
2021-07-20 05:22:29 +03:00
|
|
|
const name = 'Automated integration test';
|
2021-07-28 22:37:41 +03:00
|
|
|
const scopes = [
|
|
|
|
'CAN_SEND_SYSTEM_MESSAGES',
|
|
|
|
'CAN_SEND_MESSAGES',
|
|
|
|
'HAS_ADMIN_ACCESS',
|
|
|
|
];
|
2021-02-19 10:05:52 +03:00
|
|
|
const res = await sendIntegrationsChangePayload('accesstokens/create', {
|
|
|
|
name: name,
|
2021-07-28 22:37:41 +03:00
|
|
|
scopes: scopes,
|
2021-02-19 10:05:52 +03:00
|
|
|
});
|
|
|
|
|
2021-07-20 05:22:29 +03:00
|
|
|
expect(res.body.accessToken).toBeTruthy();
|
|
|
|
expect(res.body.createdAt).toBeTruthy();
|
|
|
|
expect(res.body.displayName).toBe(name);
|
2021-02-19 10:05:52 +03:00
|
|
|
expect(res.body.scopes).toStrictEqual(scopes);
|
2021-07-20 05:22:29 +03:00
|
|
|
accessToken = res.body.accessToken;
|
2021-07-28 22:37:41 +03:00
|
|
|
|
2021-02-19 10:05:52 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2021-07-20 05:22:29 +03:00
|
|
|
test('check access tokens', async (done) => {
|
2021-07-28 22:37:41 +03:00
|
|
|
const res = await request
|
|
|
|
.get('/api/admin/accesstokens')
|
|
|
|
.auth('admin', 'abc123')
|
|
|
|
.expect(200);
|
|
|
|
const tokenCheck = res.body.filter(
|
|
|
|
(token) => token.accessToken === accessToken
|
|
|
|
);
|
2021-07-20 05:22:29 +03:00
|
|
|
expect(tokenCheck).toHaveLength(1);
|
|
|
|
done();
|
2021-02-19 10:05:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('send a system message using access token', async (done) => {
|
2021-07-28 22:37:41 +03:00
|
|
|
const payload = {
|
|
|
|
body: 'This is a test system message from the automated integration test',
|
|
|
|
};
|
|
|
|
const res = await request
|
|
|
|
.post('/api/integrations/chat/system')
|
2021-02-19 10:05:52 +03:00
|
|
|
.set('Authorization', 'Bearer ' + accessToken)
|
2021-07-28 22:37:41 +03:00
|
|
|
.send(payload)
|
|
|
|
.expect(200);
|
2021-02-19 10:05:52 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2021-07-20 05:22:29 +03:00
|
|
|
test('send an external integration message using access token', async (done) => {
|
2021-07-28 22:37:41 +03:00
|
|
|
const payload = {
|
|
|
|
body: 'This is a test external message from the automated integration test',
|
|
|
|
};
|
|
|
|
const res = await request
|
|
|
|
.post('/api/integrations/chat/send')
|
2021-07-20 05:22:29 +03:00
|
|
|
.set('Authorization', 'Bearer ' + accessToken)
|
2021-07-28 22:37:41 +03:00
|
|
|
.send(payload)
|
|
|
|
.expect(200);
|
2021-07-20 05:22:29 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('send an external integration action using access token', async (done) => {
|
2021-07-28 22:37:41 +03:00
|
|
|
const payload = {
|
|
|
|
body: 'This is a test external action from the automated integration test',
|
|
|
|
};
|
|
|
|
const res = await request
|
|
|
|
.post('/api/integrations/chat/action')
|
2021-07-20 05:22:29 +03:00
|
|
|
.set('Authorization', 'Bearer ' + accessToken)
|
2021-07-28 22:37:41 +03:00
|
|
|
.send(payload)
|
|
|
|
.expect(200);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('test fetch chat history using access token', async (done) => {
|
|
|
|
const res = await request
|
|
|
|
.get('/api/integrations/chat')
|
|
|
|
.set('Authorization', 'Bearer ' + accessToken)
|
|
|
|
.expect(200);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test('test fetch chat history failure using invalid access token', async (done) => {
|
|
|
|
const res = await request
|
|
|
|
.get('/api/integrations/chat')
|
|
|
|
.set('Authorization', 'Bearer ' + 'invalidToken')
|
|
|
|
.expect(401);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('test fetch chat history OPTIONS request', async (done) => {
|
|
|
|
const res = await request
|
|
|
|
.options('/api/integrations/chat')
|
|
|
|
.set('Authorization', 'Bearer ' + accessToken)
|
2021-08-03 22:23:20 +03:00
|
|
|
.expect(204);
|
2021-07-20 05:22:29 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2021-02-19 10:05:52 +03:00
|
|
|
test('delete access token', async (done) => {
|
|
|
|
const res = await sendIntegrationsChangePayload('accesstokens/delete', {
|
|
|
|
token: accessToken,
|
|
|
|
});
|
|
|
|
expect(res.body.success).toBe(true);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2021-07-20 05:22:29 +03:00
|
|
|
test('check token delete was successful', async (done) => {
|
2021-07-28 22:37:41 +03:00
|
|
|
const res = await request
|
|
|
|
.get('/api/admin/accesstokens')
|
|
|
|
.auth('admin', 'abc123')
|
|
|
|
.expect(200);
|
|
|
|
const tokenCheck = res.body.filter(
|
|
|
|
(token) => token.accessToken === accessToken
|
|
|
|
);
|
2021-07-20 05:22:29 +03:00
|
|
|
expect(tokenCheck).toHaveLength(0);
|
|
|
|
done();
|
2021-02-19 10:05:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
async function sendIntegrationsChangePayload(endpoint, payload) {
|
|
|
|
const url = '/api/admin/' + endpoint;
|
2021-07-28 22:37:41 +03:00
|
|
|
const res = await request
|
|
|
|
.post(url)
|
2021-02-19 10:05:52 +03:00
|
|
|
.auth('admin', 'abc123')
|
2021-07-28 22:37:41 +03:00
|
|
|
.send(payload)
|
|
|
|
.expect(200);
|
2021-02-19 10:05:52 +03:00
|
|
|
|
2021-07-28 22:37:41 +03:00
|
|
|
return res;
|
|
|
|
}
|