add chat middleware to add new message subscription

This commit is contained in:
Moriz Wahl 2023-07-18 12:46:19 +02:00
parent 33ecc4764e
commit eed89f8c4b
2 changed files with 18 additions and 1 deletions

View File

@ -54,4 +54,7 @@ export default {
Mutation: {
CreateRoom: roomProperties,
},
Subscription: {
chatMessageAdded: messageProperties,
},
}

View File

@ -117,7 +117,7 @@ describe('Message', () => {
})
describe('user chats in room', () => {
it('returns the message and publishes subscription', async () => {
it('returns the message and publishes subscriptions', async () => {
await expect(
mutate({
mutation: createMessageMutation(),
@ -146,6 +146,20 @@ describe('Message', () => {
roomCountUpdated: '1',
userId: 'other-chatting-user',
})
expect(pubsubSpy).toBeCalledWith('CHAT_MESSAGE_ADDED', {
chatMessageAdded: expect.objectContaining({
id: expect.any(String),
content: 'Some nice message to other chatting user',
senderId: 'chatting-user',
username: 'Chatting User',
avatar: expect.any(String),
date: expect.any(String),
saved: true,
distributed: false,
seen: false,
}),
userId: 'other-chatting-user',
})
})
describe('room is updated as well', () => {