fix(test): fix test to reflect chat message updates
This commit is contained in:
parent
f9d0d66271
commit
8a4039217f
@ -11,52 +11,51 @@ var userDisplayName;
|
|||||||
const message = randomNumber(100) + ' test 123';
|
const message = randomNumber(100) + ' test 123';
|
||||||
|
|
||||||
const testMessage = {
|
const testMessage = {
|
||||||
body: message,
|
body: message,
|
||||||
type: 'CHAT',
|
type: 'CHAT',
|
||||||
};
|
};
|
||||||
|
|
||||||
test('send a chat message', async (done) => {
|
test('send a chat message', async (done) => {
|
||||||
const registration = await registerChat();
|
const registration = await registerChat();
|
||||||
const accessToken = registration.accessToken;
|
const accessToken = registration.accessToken;
|
||||||
userDisplayName = registration.displayName;
|
userDisplayName = registration.displayName;
|
||||||
|
|
||||||
sendChatMessage(testMessage, accessToken, done);
|
sendChatMessage(testMessage, accessToken, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fetch chat messages by admin', async (done) => {
|
test('fetch chat messages by admin', async (done) => {
|
||||||
const res = await getAdminResponse('chat/messages');
|
const res = await getAdminResponse('chat/messages');
|
||||||
|
const expectedBody = `<p>` + testMessage.body + `</p>`;
|
||||||
|
|
||||||
const message = res.body.filter((m) => m.body === testMessage.body)[0];
|
const message = res.body.filter((m) => m.body === expectedBody)[0];
|
||||||
if (!message) {
|
if (!message) {
|
||||||
throw new Error('Message not found');
|
throw new Error('Message not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const expectedBody = testMessage.body;
|
expect(message.body).toBe(expectedBody);
|
||||||
|
expect(message.user.displayName).toBe(userDisplayName);
|
||||||
|
expect(message.type).toBe(testMessage.type);
|
||||||
|
|
||||||
expect(message.body).toBe(expectedBody);
|
done();
|
||||||
expect(message.user.displayName).toBe(userDisplayName);
|
|
||||||
expect(message.type).toBe(testMessage.type);
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('derive display name from user header', async (done) => {
|
test('derive display name from user header', async (done) => {
|
||||||
const res = await request
|
const res = await request
|
||||||
.post('/api/chat/register')
|
.post('/api/chat/register')
|
||||||
.set('X-Forwarded-User', 'test-user')
|
.set('X-Forwarded-User', 'test-user')
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(res.body.displayName).toBe('test-user');
|
expect(res.body.displayName).toBe('test-user');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('overwrite user header derived display name with body', async (done) => {
|
test('overwrite user header derived display name with body', async (done) => {
|
||||||
const res = await request
|
const res = await request
|
||||||
.post('/api/chat/register')
|
.post('/api/chat/register')
|
||||||
.send({ displayName: 'TestUserChat' })
|
.send({ displayName: 'TestUserChat' })
|
||||||
.set('X-Forwarded-User', 'test-user')
|
.set('X-Forwarded-User', 'test-user')
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(res.body.displayName).toBe('TestUserChat');
|
expect(res.body.displayName).toBe('TestUserChat');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user