-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug and add test for bord common tool
- Loading branch information
1 parent
b521db4
commit ff52c78
Showing
2 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
apps/server/src/modules/board/service/board-common-tool.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { createMock, DeepMocked } from '@golevelup/ts-jest'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { NotFoundException } from '@nestjs/common'; | ||
import { contextExternalToolFactory } from '@modules/tool/context-external-tool/testing'; | ||
import { BoardCommonToolService } from './board-common-tool.service'; | ||
import { BoardNodeRepo } from '../repo'; | ||
import { BoardNodeService } from './board-node.service'; | ||
import { ColumnBoard, MediaBoard, AnyBoardNode } from '../domain'; | ||
|
||
import { columnBoardFactory, mediaBoardFactory } from '../testing'; | ||
|
||
describe('BoardCommonToolService', () => { | ||
let service: BoardCommonToolService; | ||
let boardNodeRepo: DeepMocked<BoardNodeRepo>; | ||
let boardNodeService: DeepMocked<BoardNodeService>; | ||
|
||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
BoardCommonToolService, | ||
{ | ||
provide: BoardNodeRepo, | ||
useValue: createMock<BoardNodeRepo>(), | ||
}, | ||
{ | ||
provide: BoardNodeService, | ||
useValue: createMock<BoardNodeService>(), | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<BoardCommonToolService>(BoardCommonToolService); | ||
boardNodeRepo = module.get(BoardNodeRepo); | ||
boardNodeService = module.get(BoardNodeService); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('countBoardUsageForExternalTools', () => { | ||
const setup = () => { | ||
const contextExternalTools = [contextExternalToolFactory.build(), contextExternalToolFactory.build()]; | ||
|
||
const boardNodes: AnyBoardNode[] = [ | ||
{ rootId: '1' } as AnyBoardNode, | ||
{ rootId: '2' } as AnyBoardNode, | ||
{ rootId: '1' } as AnyBoardNode, | ||
]; | ||
boardNodeRepo.findByContextExternalToolIds.mockResolvedValue(boardNodes); | ||
|
||
return { contextExternalTools }; | ||
}; | ||
it('should count board usage for external tools', async () => { | ||
const { contextExternalTools } = setup(); | ||
const result = await service.countBoardUsageForExternalTools(contextExternalTools); | ||
|
||
expect(result).toBe(2); | ||
}); | ||
}); | ||
|
||
describe('findByDescendant', () => { | ||
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); | ||
|
||
const result = await service.findByDescendant(boardNode); | ||
|
||
expect(result).toBe(rootNode); | ||
}); | ||
|
||
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); | ||
|
||
const result = await service.findByDescendant(boardNode); | ||
|
||
expect(result).toBe(rootNode); | ||
}); | ||
|
||
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); | ||
|
||
await expect(service.findByDescendant(boardNode)).rejects.toThrow(NotFoundException); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters