Skip to content

Commit

Permalink
renamed getfolderbyuuid function
Browse files Browse the repository at this point in the history
  • Loading branch information
larryrider committed Dec 12, 2024
1 parent 4ed3cc2 commit 7f714bd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 30 deletions.
8 changes: 3 additions & 5 deletions src/modules/file/file.usecase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ describe('FileUseCases', () => {

jest.spyOn(fileRepository, 'findByUuid').mockResolvedValueOnce(file);
jest
.spyOn(folderUseCases, 'getFolderByUuidAndUserAndNotDeleted')
.spyOn(folderUseCases, 'getFolderByUuid')
.mockResolvedValueOnce(destinationFolder);

jest
Expand Down Expand Up @@ -573,7 +573,7 @@ describe('FileUseCases', () => {

jest.spyOn(fileRepository, 'findByUuid').mockResolvedValueOnce(file);
jest
.spyOn(folderUseCases, 'getFolderByUuidAndUserAndNotDeleted')
.spyOn(folderUseCases, 'getFolderByUuid')
.mockResolvedValueOnce(mockDestinationFolder);

expect(
Expand All @@ -590,9 +590,7 @@ describe('FileUseCases', () => {

it('When a file is moved to a non existent folder, then it should throw a not found error', () => {
jest.spyOn(fileRepository, 'findByUuid').mockResolvedValueOnce(file);
jest
.spyOn(folderUseCases, 'getFolderByUuidAndUserAndNotDeleted')
.mockResolvedValueOnce(null);
jest.spyOn(folderUseCases, 'getFolderByUuid').mockResolvedValueOnce(null);
expect(
service.moveFile(userMocked, file.uuid, destinationFolder.uuid),
).rejects.toThrow(`File can not be moved to ${destinationFolder.uuid}`);
Expand Down
9 changes: 4 additions & 5 deletions src/modules/file/file.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,10 @@ export class FileUseCases {
);
}

const destinationFolder =
await this.folderUsecases.getFolderByUuidAndUserAndNotDeleted(
destinationUuid,
user,
);
const destinationFolder = await this.folderUsecases.getFolderByUuid(
destinationUuid,
user,
);
if (!destinationFolder || destinationFolder.removed === true) {
throw new UnprocessableEntityException(
`File can not be moved to ${destinationUuid}`,
Expand Down
14 changes: 5 additions & 9 deletions src/modules/folder/folder.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,7 @@ describe('FolderController', () => {

describe('getFolderContent', () => {
it('When folde content is requested and the current folder is not found, then it should throw', async () => {
jest
.spyOn(folderUseCases, 'getFolderByUuidAndUserAndNotDeleted')
.mockResolvedValue(null);
jest.spyOn(folderUseCases, 'getFolderByUuid').mockResolvedValue(null);

expect(
folderController.getFolderContent(userMocked, v4(), {
Expand Down Expand Up @@ -354,7 +352,7 @@ describe('FolderController', () => {
}));

jest
.spyOn(folderUseCases, 'getFolderByUuidAndUserAndNotDeleted')
.spyOn(folderUseCases, 'getFolderByUuid')
.mockResolvedValue(currentFolder);

jest
Expand Down Expand Up @@ -486,7 +484,7 @@ describe('FolderController', () => {
];

jest
.spyOn(folderUseCases, 'getFolderByUuidAndUserAndNotDeleted')
.spyOn(folderUseCases, 'getFolderByUuid')
.mockResolvedValue(parentFolder);
jest
.spyOn(fileUseCases, 'searchFilesInFolder')
Expand All @@ -505,7 +503,7 @@ describe('FolderController', () => {
const parentFolder = newFolder({ attributes: { uuid: folderUuid } });

jest
.spyOn(folderUseCases, 'getFolderByUuidAndUserAndNotDeleted')
.spyOn(folderUseCases, 'getFolderByUuid')
.mockResolvedValue(parentFolder);
jest.spyOn(fileUseCases, 'searchFilesInFolder').mockResolvedValue([]);

Expand All @@ -519,9 +517,7 @@ describe('FolderController', () => {
});

it('When the parent folder does not exist, then it should throw', async () => {
jest
.spyOn(folderUseCases, 'getFolderByUuidAndUserAndNotDeleted')
.mockResolvedValue(null);
jest.spyOn(folderUseCases, 'getFolderByUuid').mockResolvedValue(null);

await expect(
folderController.checkFilesExistenceInFolder(user, folderUuid, query),
Expand Down
11 changes: 5 additions & 6 deletions src/modules/folder/folder.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,10 @@ export class FolderController {
@Param('uuid') folderUuid: string,
@Body() query: CheckFileExistenceInFolderDto,
) {
const parentFolder =
await this.folderUseCases.getFolderByUuidAndUserAndNotDeleted(
folderUuid,
user,
);
const parentFolder = await this.folderUseCases.getFolderByUuid(
folderUuid,
user,
);

if (!parentFolder) {
throw new InvalidParentFolderException('Parent folder not valid!');
Expand Down Expand Up @@ -488,7 +487,7 @@ export class FolderController {
@Query() query: BasicPaginationDto,
) {
const [currentFolder, childrenFolders, files] = await Promise.all([
this.folderUseCases.getFolderByUuidAndUserAndNotDeleted(folderUuid, user),
this.folderUseCases.getFolderByUuid(folderUuid, user),
this.folderUseCases.getFolders(
user.id,
{
Expand Down
7 changes: 2 additions & 5 deletions src/modules/folder/folder.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class FolderUseCases {
return folder;
}

async getFolderByUuidAndUserAndNotDeleted(
async getFolderByUuid(
folderUuid: FolderAttributes['uuid'],
user: User,
): Promise<Folder> {
Expand Down Expand Up @@ -800,10 +800,7 @@ export class FolderUseCases {
);
}

const destinationFolder = await this.getFolderByUuidAndUserAndNotDeleted(
destinationUuid,
user,
);
const destinationFolder = await this.getFolderByUuid(destinationUuid, user);
if (destinationFolder.removed === true) {
throw new UnprocessableEntityException(
`Folder can not be moved to ${destinationUuid}`,
Expand Down

0 comments on commit 7f714bd

Please sign in to comment.