owncast/test/automated/chatmoderation.test.js
gingervitis 8a74af202d
Update chat message visibility for moderation (#524)
* update message viz in db

* create admin endpoint to update message visibility

* convert UpdateMessageVisibility api to take in an array of IDs to change visibility on instead

* Support requesting filtered or unfiltered chat messages

* Handle UPDATE chat events on front and backend for toggling messages

* Return entire message with UPDATE events

* Remove the UPDATE message type

* Revert "Remove the UPDATE message type"

This reverts commit 3a83df3d492f7ecf2bab65e845aa2b0365d3a7f6.

* update -> visibility update

* completely remove messages when they turn hidden on VISIBILITY-UPDATEs, and insert them if they turn visible

* Explicitly set visibility

* Fix multi-id sql updates

* increate scroll buffer a bit so chat scrolls when new large messages come in

* Add automated test around chat moderation

* Add new chat admin APIs to api spec

* Commit updated API documentation

Co-authored-by: Gabe Kangas <gabek@real-ity.com>
Co-authored-by: Owncast <owncast@owncast.online>
2020-12-29 13:35:33 -08:00

55 lines
1.4 KiB
JavaScript

const { test } = require('@jest/globals');
var request = require('supertest');
request = request('http://127.0.0.1:8080');
const WebSocket = require('ws');
var ws;
const testVisibilityMessage = {
author: "username",
body: "message " + Math.floor(Math.random() * 100),
type: 'CHAT',
visible: true,
timestamp: new Date().toISOString()
};
test('can send a chat message', (done) => {
ws = new WebSocket('ws://127.0.0.1:8080/entry', {
origin: 'http://localhost',
});
function onOpen() {
ws.send(JSON.stringify(testVisibilityMessage), function () {
ws.close();
done();
});
}
ws.on('open', onOpen);
});
var messageId;
test('verify we can make API call to mark message as hidden', async (done) => {
const res = await request.get('/api/chat').expect(200);
const message = res.body[0];
messageId = message.id;
await request.post('/api/admin/chat/updatemessagevisibility')
.auth('admin', 'abc123')
.send({ "idArray": [messageId], "visible": false }).expect(200);
done();
});
test('verify message has become hidden', async (done) => {
const res = await request.get('/api/admin/chat/messages')
.expect(200)
.auth('admin', 'abc123')
const message = res.body.filter(obj => {
return obj.id === messageId;
});
expect(message.length).toBe(1);
expect(message[0].visible).toBe(false);
done();
});