From 383d6c4947beca2379dd9b76b79ecd1c5e872d52 Mon Sep 17 00:00:00 2001 From: virgilchiriac Date: Thu, 13 Jun 2024 18:05:48 +0200 Subject: [PATCH] change some mocks to Once --- .../board/service/board-common-tool.service.spec.ts | 8 ++++---- .../board/service/board-node-permission.service.spec.ts | 2 +- .../modules/board/service/column-board.service.spec.ts | 8 ++++---- .../media-board/media-available-line.service.spec.ts | 4 ++-- .../board/service/media-board/media-board.service.spec.ts | 6 +++--- .../repo/mikro-orm/column-board-node.repo.spec.ts | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/apps/server/src/modules/board/service/board-common-tool.service.spec.ts b/apps/server/src/modules/board/service/board-common-tool.service.spec.ts index 319c58d1843..5895d3eb0b9 100644 --- a/apps/server/src/modules/board/service/board-common-tool.service.spec.ts +++ b/apps/server/src/modules/board/service/board-common-tool.service.spec.ts @@ -52,7 +52,7 @@ describe('BoardCommonToolService', () => { { rootId: '2' } as AnyBoardNode, { rootId: '1' } as AnyBoardNode, ]; - boardNodeRepo.findByContextExternalToolIds.mockResolvedValue(boardNodes); + boardNodeRepo.findByContextExternalToolIds.mockResolvedValueOnce(boardNodes); return { contextExternalTools }; }; @@ -68,7 +68,7 @@ describe('BoardCommonToolService', () => { it('should return the root node when it is a ColumnBoard', async () => { const boardNode: AnyBoardNode = { id: '1', rootId: '2' } as AnyBoardNode; const rootNode: ColumnBoard = columnBoardFactory.build(); - boardNodeService.findRoot.mockResolvedValue(rootNode); + boardNodeService.findRoot.mockResolvedValueOnce(rootNode); const result = await service.findByDescendant(boardNode); @@ -78,7 +78,7 @@ describe('BoardCommonToolService', () => { it('should return the root node when it is a MediaBoard', async () => { const boardNode: AnyBoardNode = { id: '1', rootId: '2' } as AnyBoardNode; const rootNode: MediaBoard = mediaBoardFactory.build(); - boardNodeService.findRoot.mockResolvedValue(rootNode); + boardNodeService.findRoot.mockResolvedValueOnce(rootNode); const result = await service.findByDescendant(boardNode); @@ -88,7 +88,7 @@ describe('BoardCommonToolService', () => { it('should throw NotFoundException when root node is not a ColumnBoard or MediaBoard', async () => { const boardNode: AnyBoardNode = { id: '1', rootId: '2' } as AnyBoardNode; const rootNode: AnyBoardNode = { id: '2' } as AnyBoardNode; - boardNodeService.findRoot.mockResolvedValue(rootNode); + boardNodeService.findRoot.mockResolvedValueOnce(rootNode); await expect(service.findByDescendant(boardNode)).rejects.toThrow(NotFoundException); }); diff --git a/apps/server/src/modules/board/service/board-node-permission.service.spec.ts b/apps/server/src/modules/board/service/board-node-permission.service.spec.ts index 7ddb77902fa..3d636d1561c 100644 --- a/apps/server/src/modules/board/service/board-node-permission.service.spec.ts +++ b/apps/server/src/modules/board/service/board-node-permission.service.spec.ts @@ -74,7 +74,7 @@ describe(BoardNodePermissionService.name, () => { it('should call authorization service to checkPermission', async () => { const { anyBoardDo, boardNodeAuthorizable, user } = setup(); - authorizationService.getUserWithPermissions.mockResolvedValue(user); + authorizationService.getUserWithPermissions.mockResolvedValueOnce(user); boardNodeAuthorizableService.getBoardAuthorizable.mockResolvedValueOnce(boardNodeAuthorizable); diff --git a/apps/server/src/modules/board/service/column-board.service.spec.ts b/apps/server/src/modules/board/service/column-board.service.spec.ts index 80ce6cfc528..a514242ea97 100644 --- a/apps/server/src/modules/board/service/column-board.service.spec.ts +++ b/apps/server/src/modules/board/service/column-board.service.spec.ts @@ -68,7 +68,7 @@ describe('ColumnBoardService', () => { it('should find ColumnBoards by external reference', async () => { const columnBoard = columnBoardFactory.build(); - repo.findByExternalReference.mockResolvedValue([columnBoard]); + repo.findByExternalReference.mockResolvedValueOnce([columnBoard]); const reference: BoardExternalReference = { type: BoardExternalReferenceType.Course, id: '1', @@ -90,7 +90,7 @@ describe('ColumnBoardService', () => { it('should delete ColumnBoards by course id', async () => { const columnBoard = columnBoardFactory.build(); - repo.findByExternalReference.mockResolvedValue([columnBoard]); + repo.findByExternalReference.mockResolvedValueOnce([columnBoard]); const reference: BoardExternalReference = { type: BoardExternalReferenceType.Course, id: '1', @@ -104,7 +104,7 @@ describe('ColumnBoardService', () => { it('should copy ColumnBoard', async () => { const copyStatus: CopyStatus = { status: CopyStatusEnum.SUCCESS, type: CopyElementType.COLUMNBOARD }; - columnBoardCopyService.copyColumnBoard.mockResolvedValue(copyStatus); + columnBoardCopyService.copyColumnBoard.mockResolvedValueOnce(copyStatus); const result = await service.copyColumnBoard({ originalColumnBoardId: '1', destinationExternalReference: { @@ -121,7 +121,7 @@ describe('ColumnBoardService', () => { const idMap = new Map(); idMap.set('1', '2'); const columnBoard = columnBoardFactory.build(); - columnBoardLinkService.swapLinkedIds.mockResolvedValue(columnBoard); + columnBoardLinkService.swapLinkedIds.mockResolvedValueOnce(columnBoard); const result = await service.swapLinkedIds('1', idMap); diff --git a/apps/server/src/modules/board/service/media-board/media-available-line.service.spec.ts b/apps/server/src/modules/board/service/media-board/media-available-line.service.spec.ts index f88bf2f0265..357478eddcc 100644 --- a/apps/server/src/modules/board/service/media-board/media-available-line.service.spec.ts +++ b/apps/server/src/modules/board/service/media-board/media-available-line.service.spec.ts @@ -96,7 +96,7 @@ describe(MediaAvailableLineService.name, () => { }); const board: MediaBoard = mediaBoardFactory.build({ children: [mediaExternalToolElement] }); - schoolExternalToolService.findSchoolExternalTools.mockResolvedValue([ + schoolExternalToolService.findSchoolExternalTools.mockResolvedValueOnce([ schoolExternalTool, usedSchoolExternalTool, ]); @@ -168,7 +168,7 @@ describe(MediaAvailableLineService.name, () => { }); mediaBoardService.findMediaElements.mockReturnValueOnce([mediaExternalToolElement]); - schoolExternalToolService.findSchoolExternalTools.mockResolvedValue([ + schoolExternalToolService.findSchoolExternalTools.mockResolvedValueOnce([ schoolExternalTool, usedSchoolExternalTool, ]); diff --git a/apps/server/src/modules/board/service/media-board/media-board.service.spec.ts b/apps/server/src/modules/board/service/media-board/media-board.service.spec.ts index bb7934c4f0a..424fceea009 100644 --- a/apps/server/src/modules/board/service/media-board/media-board.service.spec.ts +++ b/apps/server/src/modules/board/service/media-board/media-board.service.spec.ts @@ -72,14 +72,14 @@ describe('MediaBoardService', () => { const mediaLine = mediaLineFactory.build({ children: [mediaExternalToolElement] }); const mediaBoard = mediaBoardFactory.build({ children: [mediaLine] }); - contextExternalToolService.findContextExternalTools.mockResolvedValue([]); + contextExternalToolService.findContextExternalTools.mockResolvedValueOnce([]); return { schoolExternalTool, mediaBoard }; }; it('should call findContextExternalTools', async () => { const schoolExternalTool = schoolExternalToolFactory.build(); const mediaBoard = mediaBoardFactory.build(); - contextExternalToolService.findContextExternalTools.mockResolvedValue([]); + contextExternalToolService.findContextExternalTools.mockResolvedValueOnce([]); await service.checkElementExists(mediaBoard, schoolExternalTool); expect(contextExternalToolService.findContextExternalTools).toHaveBeenCalledWith({ schoolToolRef: { schoolToolId: schoolExternalTool.id }, @@ -102,7 +102,7 @@ describe('MediaBoardService', () => { const mediaLine = mediaLineFactory.build({ children: [mediaExternalToolElement] }); const mediaBoard = mediaBoardFactory.build({ children: [mediaLine] }); - contextExternalToolService.findContextExternalTools.mockResolvedValue([contextExternalTool]); + contextExternalToolService.findContextExternalTools.mockResolvedValueOnce([contextExternalTool]); return { schoolExternalTool, mediaBoard }; }; diff --git a/apps/server/src/modules/learnroom/repo/mikro-orm/column-board-node.repo.spec.ts b/apps/server/src/modules/learnroom/repo/mikro-orm/column-board-node.repo.spec.ts index e4ddf056130..c3bc7673863 100644 --- a/apps/server/src/modules/learnroom/repo/mikro-orm/column-board-node.repo.spec.ts +++ b/apps/server/src/modules/learnroom/repo/mikro-orm/column-board-node.repo.spec.ts @@ -36,7 +36,7 @@ describe('ColumnBoardNodeRepo', () => { describe('findById', () => { const setup = () => { const columnBoardNode = columnBoardFactory.build(); - em.findOneOrFail.mockResolvedValue(columnBoardNode); + em.findOneOrFail.mockResolvedValueOnce(columnBoardNode); return { columnBoardNode }; };