From fd5abd59fb3649053b5370257ac5a9dec7958349 Mon Sep 17 00:00:00 2001 From: mirarifhasan Date: Tue, 30 Jan 2024 13:15:27 +0600 Subject: [PATCH] test: updateUser test case added --- .../src/user/user.service.spec.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/hoppscotch-backend/src/user/user.service.spec.ts b/packages/hoppscotch-backend/src/user/user.service.spec.ts index 7c4fc43aa..55be97b70 100644 --- a/packages/hoppscotch-backend/src/user/user.service.spec.ts +++ b/packages/hoppscotch-backend/src/user/user.service.spec.ts @@ -414,6 +414,41 @@ describe('UserService', () => { }); }); + describe('updateUser', () => { + test('should resolve right and update user', async () => { + mockPrisma.user.update.mockResolvedValueOnce(user); + + const result = await userService.updateUser(user.uid, user.displayName); + expect(result).toEqualRight({ + ...user, + currentGQLSession: JSON.stringify(user.currentGQLSession), + currentRESTSession: JSON.stringify(user.currentRESTSession), + }); + }); + test('should resolve right and publish user updated subscription', async () => { + mockPrisma.user.update.mockResolvedValueOnce(user); + + await userService.updateUser(user.uid, user.displayName); + expect(mockPubSub.publish).toHaveBeenCalledWith( + `user/${user.uid}/updated`, + { + ...user, + currentGQLSession: JSON.stringify(user.currentGQLSession), + currentRESTSession: JSON.stringify(user.currentRESTSession), + }, + ); + }); + test('should resolve left and error when invalid user uid is passed', async () => { + mockPrisma.user.update.mockRejectedValueOnce('NotFoundError'); + + const result = await userService.updateUser( + 'invalidUserUid', + user.displayName, + ); + expect(result).toEqualLeft(USER_NOT_FOUND); + }); + }); + describe('fetchAllUsers', () => { test('should resolve right and return 20 users when cursor is null', async () => { mockPrisma.user.findMany.mockResolvedValueOnce(users);