From a82e76f3666969840952600e31a55e7cb294e304 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 13 Jul 2023 11:13:06 +0200 Subject: [PATCH] test message ordering & pagination --- backend/src/graphql/messages.ts | 1 + backend/src/schema/resolvers/messages.spec.ts | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/backend/src/graphql/messages.ts b/backend/src/graphql/messages.ts index 4d2220f18..8a17d5208 100644 --- a/backend/src/graphql/messages.ts +++ b/backend/src/graphql/messages.ts @@ -17,6 +17,7 @@ export const messageQuery = () => { Message(roomId: $roomId) { _id id + indexId content senderId username diff --git a/backend/src/schema/resolvers/messages.spec.ts b/backend/src/schema/resolvers/messages.spec.ts index a43bd3226..c7733aa9b 100644 --- a/backend/src/schema/resolvers/messages.spec.ts +++ b/backend/src/schema/resolvers/messages.spec.ts @@ -212,6 +212,7 @@ describe('Message', () => { { id: expect.any(String), _id: result.data.Message[0].id, + indexId: '0', content: 'Some nice message to other chatting user', senderId: 'chatting-user', username: 'Chatting User', @@ -256,6 +257,7 @@ describe('Message', () => { Message: expect.arrayContaining([ expect.objectContaining({ id: expect.any(String), + indexId: '0', content: 'Some nice message to other chatting user', senderId: 'chatting-user', username: 'Chatting User', @@ -264,6 +266,7 @@ describe('Message', () => { }), expect.objectContaining({ id: expect.any(String), + indexId: '1', content: 'A nice response message to chatting user', senderId: 'other-chatting-user', username: 'Other Chatting User', @@ -272,6 +275,72 @@ describe('Message', () => { }), expect.objectContaining({ id: expect.any(String), + indexId: '2', + content: 'And another nice message to other chatting user', + senderId: 'chatting-user', + username: 'Chatting User', + avatar: expect.any(String), + date: expect.any(String), + }), + ]), + }, + }) + }) + + it('returns the messages paginated', async () => { + await expect( + query({ + query: messageQuery(), + variables: { + roomId, + first: 2, + offset: 0, + orderBy: 'created_desc', + }, + }), + ).resolves.toMatchObject({ + errors: undefined, + data: { + Message: expect.arrayContaining([ + expect.objectContaining({ + id: expect.any(String), + indexId: '0', + content: 'Some nice message to other chatting user', + senderId: 'chatting-user', + username: 'Chatting User', + avatar: expect.any(String), + date: expect.any(String), + }), + expect.objectContaining({ + id: expect.any(String), + indexId: '1', + content: 'A nice response message to chatting user', + senderId: 'other-chatting-user', + username: 'Other Chatting User', + avatar: expect.any(String), + date: expect.any(String), + }), + ]), + }, + }) + + await expect( + query({ + query: messageQuery(), + variables: { + roomId, + first: 2, + offset: 2, + orderBy: 'created_desc', + }, + }), + ).resolves.toMatchObject({ + errors: undefined, + data: { + Message: expect.arrayContaining([ + expect.objectContaining({ + id: expect.any(String), + indexId: '2', content: 'And another nice message to other chatting user', senderId: 'chatting-user', username: 'Chatting User',