From a4bb523cb4d1e50abc1f3c528dc01460fabf3a7d Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 11 Jul 2023 12:57:37 +0200 Subject: [PATCH] unit test for error when creating room with self --- backend/src/schema/resolvers/rooms.spec.ts | 15 +++++++++++++++ backend/src/schema/resolvers/rooms.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/src/schema/resolvers/rooms.spec.ts b/backend/src/schema/resolvers/rooms.spec.ts index d27c64e57..03c3d4456 100644 --- a/backend/src/schema/resolvers/rooms.spec.ts +++ b/backend/src/schema/resolvers/rooms.spec.ts @@ -92,6 +92,21 @@ describe('Room', () => { }) }) + describe('user id is self', () => { + it('throws error', async () => { + await expect( + mutate({ + mutation: createRoomMutation(), + variables: { + userId: 'chatting-user', + }, + }), + ).resolves.toMatchObject({ + errors: [{ message: 'Cannot create a room with self' }], + }) + }) + }) + describe('user id exists', () => { it('returns the id of the room', async () => { const result = await mutate({ diff --git a/backend/src/schema/resolvers/rooms.ts b/backend/src/schema/resolvers/rooms.ts index 293cd6e91..d5015a03b 100644 --- a/backend/src/schema/resolvers/rooms.ts +++ b/backend/src/schema/resolvers/rooms.ts @@ -33,7 +33,7 @@ export default { user: { id: currentUserId }, } = context if (userId === currentUserId) { - throw new Error('Cannot create a room with yourself') + throw new Error('Cannot create a room with self') } const session = context.driver.session() const writeTxResultPromise = session.writeTransaction(async (transaction) => {