From 05bee2da069a805eecf3018398e8dc500ff112e2 Mon Sep 17 00:00:00 2001 From: Felipe Barreta Date: Tue, 5 Nov 2024 18:07:59 -0800 Subject: [PATCH] ALCS-2353 Test fixes --- .../tag/tag-category/tag-category.controller.spec.ts | 10 ++++------ .../alcs/tag/tag-category/tag-category.service.spec.ts | 1 + services/apps/alcs/src/alcs/tag/tag.controller.spec.ts | 1 + services/apps/alcs/src/alcs/tag/tag.service.spec.ts | 3 +++ services/package.json | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/services/apps/alcs/src/alcs/tag/tag-category/tag-category.controller.spec.ts b/services/apps/alcs/src/alcs/tag/tag-category/tag-category.controller.spec.ts index 6025f707aa..c0910e17cc 100644 --- a/services/apps/alcs/src/alcs/tag/tag-category/tag-category.controller.spec.ts +++ b/services/apps/alcs/src/alcs/tag/tag-category/tag-category.controller.spec.ts @@ -7,6 +7,7 @@ import { initTagCategoryMockEntity } from '../../../../test/mocks/mockEntities'; import { mockKeyCloakProviders } from '../../../../test/mocks/mockTypes'; import { TagCategory } from './tag-category.entity'; import { TagCategoryDto } from './tag-category.dto'; +import { UpdateResult } from 'typeorm'; describe('TagCategoryController', () => { let controller: TagCategoryController; @@ -62,20 +63,17 @@ describe('TagCategoryController', () => { name: mockCategoryTag.name, } as TagCategoryDto; - const result = await controller.update( - mockCategoryTag.uuid, - categoryToUpdate, - ); + const result = await controller.update(mockCategoryTag.uuid, categoryToUpdate); expect(tagCategoryService.update).toHaveBeenCalledTimes(1); expect(result).toEqual(mockCategoryTag); }); it('should delete a tag category', async () => { - tagCategoryService.delete.mockResolvedValue(mockCategoryTag); + tagCategoryService.delete.mockResolvedValue({} as UpdateResult); const result = await controller.delete(mockCategoryTag.uuid); expect(tagCategoryService.delete).toHaveBeenCalledTimes(1); - expect(result).toEqual(mockCategoryTag); + expect(result).toBeDefined(); }); }); diff --git a/services/apps/alcs/src/alcs/tag/tag-category/tag-category.service.spec.ts b/services/apps/alcs/src/alcs/tag/tag-category/tag-category.service.spec.ts index 9616a274e6..fb0b496d26 100644 --- a/services/apps/alcs/src/alcs/tag/tag-category/tag-category.service.spec.ts +++ b/services/apps/alcs/src/alcs/tag/tag-category/tag-category.service.spec.ts @@ -48,6 +48,7 @@ describe('TagCategoryService', () => { }).compile(); service = module.get(TagCategoryService); + tagCategoryRepositoryMock.find.mockResolvedValue([]); tagCategoryRepositoryMock.findOne.mockResolvedValue(mockTagCategoryEntity); tagCategoryRepositoryMock.findOneOrFail.mockResolvedValue(mockTagCategoryEntity); tagCategoryRepositoryMock.save.mockResolvedValue(mockTagCategoryEntity); diff --git a/services/apps/alcs/src/alcs/tag/tag.controller.spec.ts b/services/apps/alcs/src/alcs/tag/tag.controller.spec.ts index 8042769a45..7191b00adb 100644 --- a/services/apps/alcs/src/alcs/tag/tag.controller.spec.ts +++ b/services/apps/alcs/src/alcs/tag/tag.controller.spec.ts @@ -48,6 +48,7 @@ describe('TagController', () => { it('should create a tag', async () => { const dto: TagDto = { + uuid: mockTag.uuid, name: mockTag.name, category: mockTag.category ? { diff --git a/services/apps/alcs/src/alcs/tag/tag.service.spec.ts b/services/apps/alcs/src/alcs/tag/tag.service.spec.ts index b853208c7f..60a49469e7 100644 --- a/services/apps/alcs/src/alcs/tag/tag.service.spec.ts +++ b/services/apps/alcs/src/alcs/tag/tag.service.spec.ts @@ -52,6 +52,7 @@ describe('TagCategoryService', () => { tagRepositoryMock.findOneOrFail.mockResolvedValue(mockTagEntity); tagRepositoryMock.findOne.mockResolvedValue(mockTagEntity); + tagRepositoryMock.find.mockResolvedValue([]); tagRepositoryMock.save.mockResolvedValue(mockTagEntity); tagCategoryRepositoryMock.findOne.mockResolvedValue(mockTagCategoryEntity); tagCategoryRepositoryMock = module.get(getRepositoryToken(TagCategory)); @@ -67,6 +68,7 @@ describe('TagCategoryService', () => { it('should call save when an Tag is updated', async () => { const payload: TagDto = { + uuid: mockTagEntity.uuid, name: mockTagEntity.name, isActive: mockTagEntity.isActive, category: mockTagCategoryEntity, @@ -80,6 +82,7 @@ describe('TagCategoryService', () => { it('should call save when tag successfully create', async () => { const payload: TagDto = { + uuid: mockTagEntity.uuid, name: mockTagEntity.name, isActive: mockTagEntity.isActive, category: mockTagCategoryEntity, diff --git a/services/package.json b/services/package.json index 6e1f569355..9dd7c812ce 100644 --- a/services/package.json +++ b/services/package.json @@ -11,7 +11,7 @@ "format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "TZ=UTC jest", - "test:watch": "TZ=UTC jest --watch", + "test:watch": "jest --watch", "test:cov": "TZ=UTC jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "TZ=UTC jest --config apps/alcs/test/jest-e2e.json",