Automated browser testing (#1415)
* Move automated api tests to api directory * First pass at automated browser testing
This commit is contained in:
33
test/automated/api/lib/chat.js
Normal file
33
test/automated/api/lib/chat.js
Normal file
@@ -0,0 +1,33 @@
|
||||
var request = require('supertest');
|
||||
request = request('http://127.0.0.1:8080');
|
||||
const WebSocket = require('ws');
|
||||
|
||||
async function registerChat() {
|
||||
try {
|
||||
const response = await request.post('/api/chat/register');
|
||||
return response.body;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
function sendChatMessage(message, accessToken, done) {
|
||||
const ws = new WebSocket(
|
||||
`ws://localhost:8080/ws?accessToken=${accessToken}`,
|
||||
{
|
||||
origin: 'http://localhost:8080',
|
||||
}
|
||||
);
|
||||
|
||||
function onOpen() {
|
||||
ws.send(JSON.stringify(message), function () {
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
ws.on('open', onOpen);
|
||||
}
|
||||
|
||||
module.exports.sendChatMessage = sendChatMessage;
|
||||
module.exports.registerChat = registerChat;
|
||||
Reference in New Issue
Block a user