Standardize endpoint name and fix doc. Closes #1966
This commit is contained in:
@@ -7,112 +7,112 @@ const registerChat = require('./lib/chat').registerChat;
|
||||
const sendChatMessage = require('./lib/chat').sendChatMessage;
|
||||
|
||||
const testVisibilityMessage = {
|
||||
body: 'message ' + Math.floor(Math.random() * 100),
|
||||
type: 'CHAT',
|
||||
body: 'message ' + Math.floor(Math.random() * 100),
|
||||
type: 'CHAT',
|
||||
};
|
||||
|
||||
var messageId;
|
||||
|
||||
const establishedUserFailedChatMessage = {
|
||||
body: 'this message should fail to send ' + Math.floor(Math.random() * 100),
|
||||
type: 'CHAT',
|
||||
body: 'this message should fail to send ' + Math.floor(Math.random() * 100),
|
||||
type: 'CHAT',
|
||||
};
|
||||
|
||||
test('can send a chat message', async (done) => {
|
||||
const registration = await registerChat();
|
||||
const accessToken = registration.accessToken;
|
||||
const registration = await registerChat();
|
||||
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) => {
|
||||
const registration = await registerChat();
|
||||
const accessToken = registration.accessToken;
|
||||
const ws = new WebSocket(
|
||||
`ws://localhost:8080/ws?accessToken=${accessToken}`,
|
||||
{
|
||||
origin: 'http://localhost:8080',
|
||||
}
|
||||
);
|
||||
const registration = await registerChat();
|
||||
const accessToken = registration.accessToken;
|
||||
const ws = new WebSocket(
|
||||
`ws://localhost:8080/ws?accessToken=${accessToken}`,
|
||||
{
|
||||
origin: 'http://localhost:8080',
|
||||
}
|
||||
);
|
||||
|
||||
// Verify the visibility change comes through the websocket
|
||||
ws.on('message', async function incoming(message) {
|
||||
const messages = message.split('\n');
|
||||
messages.forEach(async function (message) {
|
||||
const event = JSON.parse(message);
|
||||
// Verify the visibility change comes through the websocket
|
||||
ws.on('message', async function incoming(message) {
|
||||
const messages = message.split('\n');
|
||||
messages.forEach(async function (message) {
|
||||
const event = JSON.parse(message);
|
||||
|
||||
if (event.type === 'VISIBILITY-UPDATE') {
|
||||
ws.close();
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
if (event.type === 'VISIBILITY-UPDATE') {
|
||||
ws.close();
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const res = await request
|
||||
.get('/api/admin/chat/messages')
|
||||
.auth('admin', 'abc123')
|
||||
.expect(200);
|
||||
const res = await request
|
||||
.get('/api/admin/chat/messages')
|
||||
.auth('admin', 'abc123')
|
||||
.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);
|
||||
const message = res.body[0];
|
||||
messageId = message.id;
|
||||
await request
|
||||
.post('/api/admin/chat/messagevisibility')
|
||||
.auth('admin', 'abc123')
|
||||
.send({ idArray: [messageId], visible: false })
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
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
|
||||
.get('/api/admin/chat/messages')
|
||||
.expect(200)
|
||||
.auth('admin', 'abc123');
|
||||
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].hiddenAt).toBeTruthy();
|
||||
done();
|
||||
const message = res.body.filter((obj) => {
|
||||
return obj.id === messageId;
|
||||
});
|
||||
expect(message.length).toBe(1);
|
||||
// expect(message[0].hiddenAt).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
test('can enable established chat user mode', async (done) => {
|
||||
await request
|
||||
.post('/api/admin/config/chat/establishedusermode')
|
||||
.auth('admin', 'abc123')
|
||||
.send({ value: true })
|
||||
.expect(200);
|
||||
done();
|
||||
await request
|
||||
.post('/api/admin/config/chat/establishedusermode')
|
||||
.auth('admin', 'abc123')
|
||||
.send({ value: true })
|
||||
.expect(200);
|
||||
done();
|
||||
});
|
||||
|
||||
test('can send a message after established user mode is enabled', async (done) => {
|
||||
const registration = await registerChat();
|
||||
const accessToken = registration.accessToken;
|
||||
const registration = await registerChat();
|
||||
const accessToken = registration.accessToken;
|
||||
|
||||
sendChatMessage(establishedUserFailedChatMessage, accessToken, done);
|
||||
sendChatMessage(establishedUserFailedChatMessage, accessToken, done);
|
||||
});
|
||||
|
||||
test('verify rejected message is not in the chat feed', async (done) => {
|
||||
const res = await request
|
||||
.get('/api/admin/chat/messages')
|
||||
.expect(200)
|
||||
.auth('admin', 'abc123');
|
||||
const res = await request
|
||||
.get('/api/admin/chat/messages')
|
||||
.expect(200)
|
||||
.auth('admin', 'abc123');
|
||||
|
||||
const message = res.body.filter((obj) => {
|
||||
return obj.body === establishedUserFailedChatMessage.body;
|
||||
});
|
||||
const message = res.body.filter((obj) => {
|
||||
return obj.body === establishedUserFailedChatMessage.body;
|
||||
});
|
||||
|
||||
expect(message.length).toBe(0);
|
||||
done();
|
||||
expect(message.length).toBe(0);
|
||||
done();
|
||||
});
|
||||
|
||||
test('can disable established chat user mode', async (done) => {
|
||||
await request
|
||||
.post('/api/admin/config/chat/establishedusermode')
|
||||
.auth('admin', 'abc123')
|
||||
.send({ value: false })
|
||||
.expect(200);
|
||||
done();
|
||||
await request
|
||||
.post('/api/admin/config/chat/establishedusermode')
|
||||
.auth('admin', 'abc123')
|
||||
.send({ value: false })
|
||||
.expect(200);
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user