use lib/admin.js functions in api tests (#2419)
This commit is contained in:
parent
06c80f4540
commit
12ec4b15cd
@ -1,10 +1,10 @@
|
|||||||
var request = require('supertest');
|
var request = require('supertest');
|
||||||
request = request('http://127.0.0.1:8080');
|
request = request('http://127.0.0.1:8080');
|
||||||
|
|
||||||
|
const getAdminResponse = require('./lib/admin').getAdminResponse;
|
||||||
|
|
||||||
test('correct number of log entries exist', (done) => {
|
test('correct number of log entries exist', (done) => {
|
||||||
request.get('/api/admin/logs').auth('admin', 'abc123').expect(200)
|
getAdminResponse('logs')
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
// expect(res.body).toHaveLength(8);
|
// expect(res.body).toHaveLength(8);
|
||||||
done();
|
done();
|
||||||
|
@ -4,6 +4,7 @@ request = request('http://127.0.0.1:8080');
|
|||||||
|
|
||||||
const registerChat = require('./lib/chat').registerChat;
|
const registerChat = require('./lib/chat').registerChat;
|
||||||
const sendChatMessage = require('./lib/chat').sendChatMessage;
|
const sendChatMessage = require('./lib/chat').sendChatMessage;
|
||||||
|
const getAdminResponse = require('./lib/admin').getAdminResponse;
|
||||||
|
|
||||||
var userDisplayName;
|
var userDisplayName;
|
||||||
const message = Math.floor(Math.random() * 100) + ' test 123';
|
const message = Math.floor(Math.random() * 100) + ' test 123';
|
||||||
@ -13,7 +14,7 @@ const testMessage = {
|
|||||||
type: 'CHAT',
|
type: 'CHAT',
|
||||||
};
|
};
|
||||||
|
|
||||||
test('can send a chat message', async (done) => {
|
test('send a chat message', async (done) => {
|
||||||
const registration = await registerChat();
|
const registration = await registerChat();
|
||||||
const accessToken = registration.accessToken;
|
const accessToken = registration.accessToken;
|
||||||
userDisplayName = registration.displayName;
|
userDisplayName = registration.displayName;
|
||||||
@ -21,11 +22,8 @@ test('can send a chat message', async (done) => {
|
|||||||
sendChatMessage(testMessage, accessToken, done);
|
sendChatMessage(testMessage, accessToken, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can fetch chat messages', async (done) => {
|
test('fetch chat messages by admin', async (done) => {
|
||||||
const res = await request
|
const res = await getAdminResponse('chat/messages');
|
||||||
.get('/api/admin/chat/messages')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const message = res.body.filter((m) => m.body === testMessage.body)[0];
|
const message = res.body.filter((m) => m.body === testMessage.body)[0];
|
||||||
if (!message) {
|
if (!message) {
|
||||||
@ -41,7 +39,7 @@ test('can fetch chat messages', async (done) => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can derive display name from user header', async (done) => {
|
test('derive display name from user header', async (done) => {
|
||||||
const res = await request
|
const res = await request
|
||||||
.post('/api/chat/register')
|
.post('/api/chat/register')
|
||||||
.set('X-Forwarded-User', 'test-user')
|
.set('X-Forwarded-User', 'test-user')
|
||||||
@ -51,7 +49,7 @@ test('can derive display name from user header', async (done) => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can overwrite user header derived display name with body', async (done) => {
|
test('overwrite user header derived display name with body', async (done) => {
|
||||||
const res = await request
|
const res = await request
|
||||||
.post('/api/chat/register')
|
.post('/api/chat/register')
|
||||||
.send({ displayName: 'TestUserChat' })
|
.send({ displayName: 'TestUserChat' })
|
||||||
|
@ -5,6 +5,9 @@ const WebSocket = require('ws');
|
|||||||
|
|
||||||
const registerChat = require('./lib/chat').registerChat;
|
const registerChat = require('./lib/chat').registerChat;
|
||||||
const sendChatMessage = require('./lib/chat').sendChatMessage;
|
const sendChatMessage = require('./lib/chat').sendChatMessage;
|
||||||
|
const getAdminResponse = require('./lib/admin').getAdminResponse;
|
||||||
|
const sendAdminPayload = require('./lib/admin').sendAdminPayload;
|
||||||
|
const sendAdminRequest = require('./lib/admin').sendAdminRequest;
|
||||||
|
|
||||||
const testVisibilityMessage = {
|
const testVisibilityMessage = {
|
||||||
body: 'message ' + Math.floor(Math.random() * 100),
|
body: 'message ' + Math.floor(Math.random() * 100),
|
||||||
@ -18,14 +21,14 @@ const establishedUserFailedChatMessage = {
|
|||||||
type: 'CHAT',
|
type: 'CHAT',
|
||||||
};
|
};
|
||||||
|
|
||||||
test('can send a chat message', async (done) => {
|
test('send a chat message', async (done) => {
|
||||||
const registration = await registerChat();
|
const registration = await registerChat();
|
||||||
const accessToken = registration.accessToken;
|
const accessToken = registration.accessToken;
|
||||||
|
|
||||||
sendChatMessage(testVisibilityMessage, accessToken, done);
|
sendChatMessage(testVisibilityMessage, accessToken, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('verify we can make API call to mark message as hidden', async (done) => {
|
test('verify admin can make API call to mark message as hidden', async (done) => {
|
||||||
const registration = await registerChat();
|
const registration = await registerChat();
|
||||||
const accessToken = registration.accessToken;
|
const accessToken = registration.accessToken;
|
||||||
const ws = new WebSocket(
|
const ws = new WebSocket(
|
||||||
@ -48,27 +51,17 @@ test('verify we can make API call to mark message as hidden', async (done) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await request
|
const res = await getAdminResponse('chat/messages');
|
||||||
.get('/api/admin/chat/messages')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const message = res.body[0];
|
const message = res.body[0];
|
||||||
messageId = message.id;
|
messageId = message.id;
|
||||||
await request
|
await sendAdminPayload('chat/messagevisibility', { idArray: [messageId], visible: false });
|
||||||
.post('/api/admin/chat/messagevisibility')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.send({ idArray: [messageId], visible: false })
|
|
||||||
.expect(200);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('verify message has become hidden', async (done) => {
|
test('verify message has become hidden', async (done) => {
|
||||||
await new Promise((r) => setTimeout(r, 2000));
|
await new Promise((r) => setTimeout(r, 2000));
|
||||||
|
|
||||||
const res = await request
|
const res = await getAdminResponse('chat/messages');
|
||||||
.get('/api/admin/chat/messages')
|
|
||||||
.expect(200)
|
|
||||||
.auth('admin', 'abc123');
|
|
||||||
|
|
||||||
const message = res.body.filter((obj) => {
|
const message = res.body.filter((obj) => {
|
||||||
return obj.id === messageId;
|
return obj.id === messageId;
|
||||||
@ -78,16 +71,12 @@ test('verify message has become hidden', async (done) => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can enable established chat user mode', async (done) => {
|
test('enable established chat user mode', async (done) => {
|
||||||
await request
|
await sendAdminRequest('config/chat/establishedusermode', true);
|
||||||
.post('/api/admin/config/chat/establishedusermode')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.send({ value: true })
|
|
||||||
.expect(200);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can send a message after established user mode is enabled', async (done) => {
|
test('send a message after established user mode is enabled', async (done) => {
|
||||||
const registration = await registerChat();
|
const registration = await registerChat();
|
||||||
const accessToken = registration.accessToken;
|
const accessToken = registration.accessToken;
|
||||||
|
|
||||||
@ -95,10 +84,7 @@ test('can send a message after established user mode is enabled', async (done) =
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('verify rejected message is not in the chat feed', async (done) => {
|
test('verify rejected message is not in the chat feed', async (done) => {
|
||||||
const res = await request
|
const res = await getAdminResponse('chat/messages');
|
||||||
.get('/api/admin/chat/messages')
|
|
||||||
.expect(200)
|
|
||||||
.auth('admin', 'abc123');
|
|
||||||
|
|
||||||
const message = res.body.filter((obj) => {
|
const message = res.body.filter((obj) => {
|
||||||
return obj.body === establishedUserFailedChatMessage.body;
|
return obj.body === establishedUserFailedChatMessage.body;
|
||||||
@ -108,11 +94,7 @@ test('verify rejected message is not in the chat feed', async (done) => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can disable established chat user mode', async (done) => {
|
test('disable established chat user mode', async (done) => {
|
||||||
await request
|
await sendAdminRequest('config/chat/establishedusermode', false);
|
||||||
.post('/api/admin/config/chat/establishedusermode')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.send({ value: false })
|
|
||||||
.expect(200);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
var request = require('supertest');
|
var request = require('supertest');
|
||||||
request = request('http://127.0.0.1:8080');
|
request = request('http://127.0.0.1:8080');
|
||||||
|
|
||||||
|
const getAdminResponse = require('./lib/admin').getAdminResponse;
|
||||||
|
const sendAdminPayload = require('./lib/admin').sendAdminPayload;
|
||||||
|
|
||||||
var accessToken = '';
|
var accessToken = '';
|
||||||
var webhookID;
|
var webhookID;
|
||||||
|
|
||||||
@ -8,7 +11,7 @@ const webhook = 'https://super.duper.cool.thing.biz/owncast';
|
|||||||
const events = ['CHAT'];
|
const events = ['CHAT'];
|
||||||
|
|
||||||
test('create webhook', async (done) => {
|
test('create webhook', async (done) => {
|
||||||
const res = await sendIntegrationsChangePayload('webhooks/create', {
|
const res = await sendAdminPayload('webhooks/create', {
|
||||||
url: webhook,
|
url: webhook,
|
||||||
events: events,
|
events: events,
|
||||||
});
|
});
|
||||||
@ -20,10 +23,8 @@ test('create webhook', async (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('check webhooks', (done) => {
|
test('check webhooks', (done) => {
|
||||||
request
|
|
||||||
.get('/api/admin/webhooks')
|
getAdminResponse('webhooks')
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200)
|
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
expect(res.body).toHaveLength(1);
|
expect(res.body).toHaveLength(1);
|
||||||
expect(res.body[0].url).toBe(webhook);
|
expect(res.body[0].url).toBe(webhook);
|
||||||
@ -34,7 +35,7 @@ test('check webhooks', (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('delete webhook', async (done) => {
|
test('delete webhook', async (done) => {
|
||||||
const res = await sendIntegrationsChangePayload('webhooks/delete', {
|
const res = await sendAdminPayload('webhooks/delete', {
|
||||||
id: webhookID,
|
id: webhookID,
|
||||||
});
|
});
|
||||||
expect(res.body.success).toBe(true);
|
expect(res.body.success).toBe(true);
|
||||||
@ -42,10 +43,7 @@ test('delete webhook', async (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('check that webhook was deleted', (done) => {
|
test('check that webhook was deleted', (done) => {
|
||||||
request
|
getAdminResponse('webhooks')
|
||||||
.get('/api/admin/webhooks')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200)
|
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
expect(res.body).toHaveLength(0);
|
expect(res.body).toHaveLength(0);
|
||||||
done();
|
done();
|
||||||
@ -59,7 +57,7 @@ test('create access token', async (done) => {
|
|||||||
'CAN_SEND_MESSAGES',
|
'CAN_SEND_MESSAGES',
|
||||||
'HAS_ADMIN_ACCESS',
|
'HAS_ADMIN_ACCESS',
|
||||||
];
|
];
|
||||||
const res = await sendIntegrationsChangePayload('accesstokens/create', {
|
const res = await sendAdminPayload('accesstokens/create', {
|
||||||
name: name,
|
name: name,
|
||||||
scopes: scopes,
|
scopes: scopes,
|
||||||
});
|
});
|
||||||
@ -74,10 +72,7 @@ test('create access token', async (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('check access tokens', async (done) => {
|
test('check access tokens', async (done) => {
|
||||||
const res = await request
|
const res = await getAdminResponse('accesstokens');
|
||||||
.get('/api/admin/accesstokens')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
const tokenCheck = res.body.filter(
|
const tokenCheck = res.body.filter(
|
||||||
(token) => token.accessToken === accessToken
|
(token) => token.accessToken === accessToken
|
||||||
);
|
);
|
||||||
@ -146,7 +141,7 @@ test('test fetch chat history OPTIONS request', async (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('delete access token', async (done) => {
|
test('delete access token', async (done) => {
|
||||||
const res = await sendIntegrationsChangePayload('accesstokens/delete', {
|
const res = await sendAdminPayload('accesstokens/delete', {
|
||||||
token: accessToken,
|
token: accessToken,
|
||||||
});
|
});
|
||||||
expect(res.body.success).toBe(true);
|
expect(res.body.success).toBe(true);
|
||||||
@ -154,10 +149,7 @@ test('delete access token', async (done) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('check token delete was successful', async (done) => {
|
test('check token delete was successful', async (done) => {
|
||||||
const res = await request
|
const res = await getAdminResponse('accesstokens');
|
||||||
.get('/api/admin/accesstokens')
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.expect(200);
|
|
||||||
const tokenCheck = res.body.filter(
|
const tokenCheck = res.body.filter(
|
||||||
(token) => token.accessToken === accessToken
|
(token) => token.accessToken === accessToken
|
||||||
);
|
);
|
||||||
@ -165,13 +157,3 @@ test('check token delete was successful', async (done) => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
async function sendIntegrationsChangePayload(endpoint, payload) {
|
|
||||||
const url = '/api/admin/' + endpoint;
|
|
||||||
const res = await request
|
|
||||||
.post(url)
|
|
||||||
.auth('admin', 'abc123')
|
|
||||||
.send(payload)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user