* Add support for established user mode. #1587 * Tweak tests * Tweak tests * Update test * Fix test.
This commit is contained in:
@@ -27,10 +27,12 @@ test('can fetch chat messages', async (done) => {
|
||||
.auth('admin', 'abc123')
|
||||
.expect(200);
|
||||
|
||||
const expectedBody = `${testMessage.body}`;
|
||||
const message = res.body.filter(function (msg) {
|
||||
return msg.body === expectedBody;
|
||||
})[0];
|
||||
const message = res.body.filter((m) => m.body === testMessage.body)[0];
|
||||
if (!message) {
|
||||
throw new Error('Message not found');
|
||||
}
|
||||
|
||||
const expectedBody = testMessage.body;
|
||||
|
||||
expect(message.body).toBe(expectedBody);
|
||||
expect(message.user.displayName).toBe(userDisplayName);
|
||||
@@ -52,7 +54,7 @@ test('can derive display name from user header', async (done) => {
|
||||
test('can overwrite user header derived display name with body', async (done) => {
|
||||
const res = await request
|
||||
.post('/api/chat/register')
|
||||
.send({displayName: 'TestUserChat'})
|
||||
.send({ displayName: 'TestUserChat' })
|
||||
.set('X-Forwarded-User', 'test-user')
|
||||
.expect(200);
|
||||
|
||||
|
||||
@@ -5,13 +5,19 @@ const WebSocket = require('ws');
|
||||
|
||||
const registerChat = require('./lib/chat').registerChat;
|
||||
const sendChatMessage = require('./lib/chat').sendChatMessage;
|
||||
const listenForEvent = require('./lib/chat').listenForEvent;
|
||||
|
||||
const testVisibilityMessage = {
|
||||
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',
|
||||
};
|
||||
|
||||
test('can send a chat message', async (done) => {
|
||||
const registration = await registerChat();
|
||||
const accessToken = registration.accessToken;
|
||||
@@ -30,14 +36,14 @@ test('verify we can make API call to mark message as hidden', async (done) => {
|
||||
);
|
||||
|
||||
// Verify the visibility change comes through the websocket
|
||||
ws.on('message', function incoming(message) {
|
||||
ws.on('message', async function incoming(message) {
|
||||
const messages = message.split('\n');
|
||||
messages.forEach(function (message) {
|
||||
messages.forEach(async function (message) {
|
||||
const event = JSON.parse(message);
|
||||
|
||||
if (event.type === 'VISIBILITY-UPDATE') {
|
||||
done();
|
||||
ws.close();
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -48,7 +54,7 @@ test('verify we can make API call to mark message as hidden', async (done) => {
|
||||
.expect(200);
|
||||
|
||||
const message = res.body[0];
|
||||
const messageId = message.id;
|
||||
messageId = message.id;
|
||||
await request
|
||||
.post('/api/admin/chat/updatemessagevisibility')
|
||||
.auth('admin', 'abc123')
|
||||
@@ -57,15 +63,56 @@ test('verify we can make API call to mark message as hidden', async (done) => {
|
||||
});
|
||||
|
||||
test('verify message has become hidden', async (done) => {
|
||||
await new Promise((r) => setTimeout(r, 2000));
|
||||
|
||||
const res = await request
|
||||
.get('/api/admin/chat/messages')
|
||||
.expect(200)
|
||||
.auth('admin', 'abc123');
|
||||
|
||||
const message = res.body.filter((obj) => {
|
||||
return obj.body === `${testVisibilityMessage.body}`;
|
||||
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();
|
||||
});
|
||||
|
||||
test('can send a message after established user mode is enabled', async (done) => {
|
||||
const registration = await registerChat();
|
||||
const accessToken = registration.accessToken;
|
||||
|
||||
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 message = res.body.filter((obj) => {
|
||||
return obj.body === establishedUserFailedChatMessage.body;
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
@@ -11,16 +11,11 @@ async function registerChat() {
|
||||
}
|
||||
}
|
||||
|
||||
function sendChatMessage(message, accessToken, done) {
|
||||
const ws = new WebSocket(
|
||||
`ws://localhost:8080/ws?accessToken=${accessToken}`,
|
||||
{
|
||||
origin: 'http://localhost:8080',
|
||||
}
|
||||
);
|
||||
async function sendChatMessage(message, accessToken, done) {
|
||||
const ws = new WebSocket(`ws://localhost:8080/ws?accessToken=${accessToken}`);
|
||||
|
||||
function onOpen() {
|
||||
ws.send(JSON.stringify(message), function () {
|
||||
async function onOpen() {
|
||||
ws.send(JSON.stringify(message), async function () {
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
@@ -30,12 +25,7 @@ function sendChatMessage(message, accessToken, done) {
|
||||
}
|
||||
|
||||
async function listenForEvent(name, accessToken, done) {
|
||||
const ws = new WebSocket(
|
||||
`ws://localhost:8080/ws?accessToken=${accessToken}`,
|
||||
{
|
||||
origin: 'http://localhost:8080',
|
||||
}
|
||||
);
|
||||
const ws = new WebSocket(`ws://localhost:8080/ws?accessToken=${accessToken}`);
|
||||
|
||||
ws.on('message', function incoming(message) {
|
||||
const messages = message.split('\n');
|
||||
|
||||
92
test/automated/api/package-lock.json
generated
92
test/automated/api/package-lock.json
generated
@@ -600,6 +600,15 @@
|
||||
"node": ">= 10.14.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@jest/core/node_modules/ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/@jest/core/node_modules/strip-ansi": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
|
||||
@@ -984,15 +993,6 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/ansi-regex": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/ansi-styles": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||
@@ -3373,6 +3373,15 @@
|
||||
"node": ">= 10.14.2"
|
||||
}
|
||||
},
|
||||
"node_modules/jest-runtime/node_modules/ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/jest-runtime/node_modules/cliui": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz",
|
||||
@@ -3638,6 +3647,15 @@
|
||||
"node": ">= 10.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/jest/node_modules/ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/jest/node_modules/cliui": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz",
|
||||
@@ -4613,6 +4631,15 @@
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/pretty-format/node_modules/ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/prompts": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.0.tgz",
|
||||
@@ -5634,6 +5661,15 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/string-length/node_modules/ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/string-length/node_modules/strip-ansi": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
|
||||
@@ -6791,6 +6827,12 @@
|
||||
"strip-ansi": "^6.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
||||
"dev": true
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
|
||||
@@ -7132,12 +7174,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"ansi-regex": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||
"dev": true
|
||||
},
|
||||
"ansi-styles": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||
@@ -8688,6 +8724,12 @@
|
||||
"jest-cli": "^26.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
||||
"dev": true
|
||||
},
|
||||
"cliui": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz",
|
||||
@@ -9211,6 +9253,12 @@
|
||||
"yargs": "^15.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
||||
"dev": true
|
||||
},
|
||||
"cliui": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz",
|
||||
@@ -10062,6 +10110,14 @@
|
||||
"ansi-regex": "^5.0.0",
|
||||
"ansi-styles": "^4.0.0",
|
||||
"react-is": "^17.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"prompts": {
|
||||
@@ -10907,6 +10963,12 @@
|
||||
"strip-ansi": "^6.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
||||
"dev": true
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
|
||||
|
||||
Reference in New Issue
Block a user