From 4e188f3c11d8c311fcfe330270e0092ae64ce11b Mon Sep 17 00:00:00 2001 From: Mir Arif Hasan Date: Fri, 24 Nov 2023 19:20:11 +0600 Subject: [PATCH] test: fix test case failure --- .../infra-config/infra-config.service.spec.ts | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/hoppscotch-backend/src/infra-config/infra-config.service.spec.ts b/packages/hoppscotch-backend/src/infra-config/infra-config.service.spec.ts index 9357d6b14..c7fb4075a 100644 --- a/packages/hoppscotch-backend/src/infra-config/infra-config.service.spec.ts +++ b/packages/hoppscotch-backend/src/infra-config/infra-config.service.spec.ts @@ -3,12 +3,18 @@ import { PrismaService } from 'src/prisma/prisma.service'; import { InfraConfigService } from './infra-config.service'; import { InfraConfigEnum } from 'src/types/InfraConfig'; import { INFRA_CONFIG_NOT_FOUND } from 'src/errors'; +import { ConfigService } from '@nestjs/config'; +import * as helper from './helper'; const mockPrisma = mockDeep(); +const mockConfigService = mockDeep(); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore -const infraConfigService = new InfraConfigService(mockPrisma); +const infraConfigService = new InfraConfigService( + mockPrisma, + mockConfigService, +); beforeEach(() => { mockReset(mockPrisma); @@ -17,7 +23,7 @@ beforeEach(() => { describe('InfraConfigService', () => { describe('update', () => { it('should update the infra config', async () => { - const name = InfraConfigEnum.EULAConfig; + const name = InfraConfigEnum.GOOGLE_CLIENT_ID; const value = 'true'; mockPrisma.infraConfig.update.mockResolvedValueOnce({ @@ -28,14 +34,18 @@ describe('InfraConfigService', () => { createdOn: new Date(), updatedOn: new Date(), }); + jest.spyOn(helper, 'stopApp').mockReturnValueOnce(); + const result = await infraConfigService.update(name, value); expect(result).toEqualRight({ name, value }); }); it('should pass correct params to prisma update', async () => { - const name = InfraConfigEnum.EULAConfig; + const name = InfraConfigEnum.GOOGLE_CLIENT_ID; const value = 'true'; + jest.spyOn(helper, 'stopApp').mockReturnValueOnce(); + await infraConfigService.update(name, value); expect(mockPrisma.infraConfig.update).toHaveBeenCalledWith({ @@ -46,7 +56,7 @@ describe('InfraConfigService', () => { }); it('should throw an error if the infra config does not exist', async () => { - const name = InfraConfigEnum.EULAConfig; + const name = InfraConfigEnum.GOOGLE_CLIENT_ID; const value = 'true'; mockPrisma.infraConfig.update.mockRejectedValueOnce('null'); @@ -58,7 +68,7 @@ describe('InfraConfigService', () => { describe('get', () => { it('should get the infra config', async () => { - const name = InfraConfigEnum.EULAConfig; + const name = InfraConfigEnum.GOOGLE_CLIENT_ID; const value = 'true'; mockPrisma.infraConfig.findUniqueOrThrow.mockResolvedValueOnce({ @@ -74,7 +84,7 @@ describe('InfraConfigService', () => { }); it('should pass correct params to prisma findUnique', async () => { - const name = InfraConfigEnum.EULAConfig; + const name = InfraConfigEnum.GOOGLE_CLIENT_ID; await infraConfigService.get(name); @@ -85,7 +95,7 @@ describe('InfraConfigService', () => { }); it('should throw an error if the infra config does not exist', async () => { - const name = InfraConfigEnum.EULAConfig; + const name = InfraConfigEnum.GOOGLE_CLIENT_ID; mockPrisma.infraConfig.findUniqueOrThrow.mockRejectedValueOnce('null');