Skip to content

Commit

Permalink
added findFolderByUuidAndUser repository tests
Browse files Browse the repository at this point in the history
  • Loading branch information
larryrider committed Dec 12, 2024
1 parent 06299e6 commit 4ed3cc2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/modules/folder/folder.repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { newFolder } from '../../../test/fixtures';
import { FileStatus } from '../file/file.domain';
import { Op } from 'sequelize';
import { WorkspaceItemUserModel } from '../workspaces/models/workspace-items-users.model';
import { v4 } from 'uuid';
import { randomInt } from 'crypto';

jest.mock('./folder.model', () => ({
FolderModel: {
Expand Down Expand Up @@ -209,4 +211,41 @@ describe('SequelizeFolderRepository', () => {
expect(result).toEqual([]);
});
});

describe('findByUuidAndUser', () => {
it('When folders are searched by uuid and user, then it should be handle as expected', async () => {
const randomFolderUUID = v4();
const randomUserId = randomInt(100000);

await repository.findByUuidAndUser(randomFolderUUID, randomUserId);

expect(folderModel.findOne).toHaveBeenCalledWith({
where: {
uuid: randomFolderUUID,
userId: randomUserId,
removed: false,
},
});
});

it('When folders are searched by uuid and user but they dont exist, then it should return null', async () => {
const randomFolderUUID = v4();
const randomUserId = randomInt(100000);
jest.spyOn(folderModel, 'findOne').mockResolvedValueOnce(null);

const result = await repository.findByUuidAndUser(
randomFolderUUID,
randomUserId,
);

expect(folderModel.findOne).toHaveBeenCalledWith({
where: {
uuid: randomFolderUUID,
userId: randomUserId,
removed: false,
},
});
expect(result).toBeNull();
});
});
});

0 comments on commit 4ed3cc2

Please sign in to comment.