test: fix test case failure
This commit is contained in:
@@ -3,12 +3,18 @@ import { PrismaService } from 'src/prisma/prisma.service';
|
|||||||
import { InfraConfigService } from './infra-config.service';
|
import { InfraConfigService } from './infra-config.service';
|
||||||
import { InfraConfigEnum } from 'src/types/InfraConfig';
|
import { InfraConfigEnum } from 'src/types/InfraConfig';
|
||||||
import { INFRA_CONFIG_NOT_FOUND } from 'src/errors';
|
import { INFRA_CONFIG_NOT_FOUND } from 'src/errors';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import * as helper from './helper';
|
||||||
|
|
||||||
const mockPrisma = mockDeep<PrismaService>();
|
const mockPrisma = mockDeep<PrismaService>();
|
||||||
|
const mockConfigService = mockDeep<ConfigService>();
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const infraConfigService = new InfraConfigService(mockPrisma);
|
const infraConfigService = new InfraConfigService(
|
||||||
|
mockPrisma,
|
||||||
|
mockConfigService,
|
||||||
|
);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockReset(mockPrisma);
|
mockReset(mockPrisma);
|
||||||
@@ -17,7 +23,7 @@ beforeEach(() => {
|
|||||||
describe('InfraConfigService', () => {
|
describe('InfraConfigService', () => {
|
||||||
describe('update', () => {
|
describe('update', () => {
|
||||||
it('should update the infra config', async () => {
|
it('should update the infra config', async () => {
|
||||||
const name = InfraConfigEnum.EULAConfig;
|
const name = InfraConfigEnum.GOOGLE_CLIENT_ID;
|
||||||
const value = 'true';
|
const value = 'true';
|
||||||
|
|
||||||
mockPrisma.infraConfig.update.mockResolvedValueOnce({
|
mockPrisma.infraConfig.update.mockResolvedValueOnce({
|
||||||
@@ -28,14 +34,18 @@ describe('InfraConfigService', () => {
|
|||||||
createdOn: new Date(),
|
createdOn: new Date(),
|
||||||
updatedOn: new Date(),
|
updatedOn: new Date(),
|
||||||
});
|
});
|
||||||
|
jest.spyOn(helper, 'stopApp').mockReturnValueOnce();
|
||||||
|
|
||||||
const result = await infraConfigService.update(name, value);
|
const result = await infraConfigService.update(name, value);
|
||||||
expect(result).toEqualRight({ name, value });
|
expect(result).toEqualRight({ name, value });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should pass correct params to prisma update', async () => {
|
it('should pass correct params to prisma update', async () => {
|
||||||
const name = InfraConfigEnum.EULAConfig;
|
const name = InfraConfigEnum.GOOGLE_CLIENT_ID;
|
||||||
const value = 'true';
|
const value = 'true';
|
||||||
|
|
||||||
|
jest.spyOn(helper, 'stopApp').mockReturnValueOnce();
|
||||||
|
|
||||||
await infraConfigService.update(name, value);
|
await infraConfigService.update(name, value);
|
||||||
|
|
||||||
expect(mockPrisma.infraConfig.update).toHaveBeenCalledWith({
|
expect(mockPrisma.infraConfig.update).toHaveBeenCalledWith({
|
||||||
@@ -46,7 +56,7 @@ describe('InfraConfigService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if the infra config does not exist', async () => {
|
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';
|
const value = 'true';
|
||||||
|
|
||||||
mockPrisma.infraConfig.update.mockRejectedValueOnce('null');
|
mockPrisma.infraConfig.update.mockRejectedValueOnce('null');
|
||||||
@@ -58,7 +68,7 @@ describe('InfraConfigService', () => {
|
|||||||
|
|
||||||
describe('get', () => {
|
describe('get', () => {
|
||||||
it('should get the infra config', async () => {
|
it('should get the infra config', async () => {
|
||||||
const name = InfraConfigEnum.EULAConfig;
|
const name = InfraConfigEnum.GOOGLE_CLIENT_ID;
|
||||||
const value = 'true';
|
const value = 'true';
|
||||||
|
|
||||||
mockPrisma.infraConfig.findUniqueOrThrow.mockResolvedValueOnce({
|
mockPrisma.infraConfig.findUniqueOrThrow.mockResolvedValueOnce({
|
||||||
@@ -74,7 +84,7 @@ describe('InfraConfigService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should pass correct params to prisma findUnique', async () => {
|
it('should pass correct params to prisma findUnique', async () => {
|
||||||
const name = InfraConfigEnum.EULAConfig;
|
const name = InfraConfigEnum.GOOGLE_CLIENT_ID;
|
||||||
|
|
||||||
await infraConfigService.get(name);
|
await infraConfigService.get(name);
|
||||||
|
|
||||||
@@ -85,7 +95,7 @@ describe('InfraConfigService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if the infra config does not exist', async () => {
|
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');
|
mockPrisma.infraConfig.findUniqueOrThrow.mockRejectedValueOnce('null');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user