From 4ed3cc2f7ccdb320bca2015ce5fffa2c4e3babbc Mon Sep 17 00:00:00 2001 From: larryrider Date: Thu, 12 Dec 2024 12:55:15 +0100 Subject: [PATCH] added findFolderByUuidAndUser repository tests --- src/modules/folder/folder.repository.spec.ts | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/modules/folder/folder.repository.spec.ts b/src/modules/folder/folder.repository.spec.ts index 6f4f80e1..3b5c72a1 100644 --- a/src/modules/folder/folder.repository.spec.ts +++ b/src/modules/folder/folder.repository.spec.ts @@ -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: { @@ -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(); + }); + }); });