Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
uidp committed Jun 12, 2024
1 parent 4187310 commit c00d4cf
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { createMock } from '@golevelup/ts-jest';
import { ObjectId } from '@mikro-orm/mongodb';
import { FileRecordParentType } from '@src/infra/rabbitmq';
import { FilesStorageClientAdapterService } from '@src/modules/files-storage-client';
import { BoardNodeCopyContext } from './board-node-copy-context';

describe(BoardNodeCopyContext.name, () => {
describe('copyFilesOfParent', () => {
const setup = () => {
const contextProps = {
sourceSchoolId: new ObjectId().toHexString(),
targetSchoolId: new ObjectId().toHexString(),
userId: new ObjectId().toHexString(),
filesStorageClientAdapterService: createMock<FilesStorageClientAdapterService>(),
};

const copyContext = new BoardNodeCopyContext(contextProps);

const sourceParentId = new ObjectId().toHexString();
const targetParentId = new ObjectId().toHexString();

return { contextProps, copyContext, sourceParentId, targetParentId };
};

it('should use the service to copy the files', async () => {
const { contextProps, copyContext, sourceParentId, targetParentId } = setup();

await copyContext.copyFilesOfParent(sourceParentId, targetParentId);

expect(contextProps.filesStorageClientAdapterService.copyFilesOfParent).toHaveBeenCalledWith({
source: {
parentId: sourceParentId,
parentType: FileRecordParentType.BoardNode,
schoolId: contextProps.sourceSchoolId,
},
target: {
parentId: targetParentId,
parentType: FileRecordParentType.BoardNode,
schoolId: contextProps.targetSchoolId,
},
userId: contextProps.userId,
});
});
});
});

0 comments on commit c00d4cf

Please sign in to comment.