Add test to verify websocket events come through for changing message visibility

This commit is contained in:
Gabe Kangas
2021-11-11 13:17:00 -08:00
parent b9107eab12
commit a33646e59f
3 changed files with 77 additions and 26 deletions

View File

@ -29,5 +29,27 @@ function sendChatMessage(message, accessToken, done) {
ws.on('open', onOpen);
}
async function listenForEvent(name, accessToken, done) {
const ws = new WebSocket(
`ws://localhost:8080/ws?accessToken=${accessToken}`,
{
origin: 'http://localhost:8080',
}
);
ws.on('message', function incoming(message) {
const messages = message.split('\n');
messages.forEach(function (message) {
const event = JSON.parse(message);
if (event.type === name) {
done();
ws.close();
}
});
});
}
module.exports.sendChatMessage = sendChatMessage;
module.exports.registerChat = registerChat;
module.exports.registerChat = registerChat;
module.exports.listenForEvent = listenForEvent;