Skip to content

Commit

Permalink
change some mocks to Once
Browse files Browse the repository at this point in the history
  • Loading branch information
virgilchiriac committed Jun 13, 2024
1 parent 3ab920d commit 383d6c4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('BoardCommonToolService', () => {
{ rootId: '2' } as AnyBoardNode,
{ rootId: '1' } as AnyBoardNode,
];
boardNodeRepo.findByContextExternalToolIds.mockResolvedValue(boardNodes);
boardNodeRepo.findByContextExternalToolIds.mockResolvedValueOnce(boardNodes);

return { contextExternalTools };
};
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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: {
Expand All @@ -121,7 +121,7 @@ describe('ColumnBoardService', () => {
const idMap = new Map<EntityId, EntityId>();
idMap.set('1', '2');
const columnBoard = columnBoardFactory.build();
columnBoardLinkService.swapLinkedIds.mockResolvedValue(columnBoard);
columnBoardLinkService.swapLinkedIds.mockResolvedValueOnce(columnBoard);

const result = await service.swapLinkedIds('1', idMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe(MediaAvailableLineService.name, () => {
});
const board: MediaBoard = mediaBoardFactory.build({ children: [mediaExternalToolElement] });

schoolExternalToolService.findSchoolExternalTools.mockResolvedValue([
schoolExternalToolService.findSchoolExternalTools.mockResolvedValueOnce([
schoolExternalTool,
usedSchoolExternalTool,
]);
Expand Down Expand Up @@ -168,7 +168,7 @@ describe(MediaAvailableLineService.name, () => {
});
mediaBoardService.findMediaElements.mockReturnValueOnce([mediaExternalToolElement]);

schoolExternalToolService.findSchoolExternalTools.mockResolvedValue([
schoolExternalToolService.findSchoolExternalTools.mockResolvedValueOnce([
schoolExternalTool,
usedSchoolExternalTool,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('ColumnBoardNodeRepo', () => {
describe('findById', () => {
const setup = () => {
const columnBoardNode = columnBoardFactory.build();
em.findOneOrFail.mockResolvedValue(columnBoardNode);
em.findOneOrFail.mockResolvedValueOnce(columnBoardNode);

return { columnBoardNode };
};
Expand Down

0 comments on commit 383d6c4

Please sign in to comment.