Skip to content

Commit

Permalink
changed usermocked to user fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
larryrider committed Dec 12, 2024
1 parent 7f714bd commit 27e8be8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
26 changes: 6 additions & 20 deletions src/modules/folder/folder.usecase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1417,12 +1417,13 @@ describe('FolderUseCases', () => {
});

describe('getFolderByUuidAndUser', () => {
const mockUser = newUser();
const mockFolder = newFolder({
attributes: {
userId: userMocked.id,
user: userMocked,
userId: mockUser.id,
user: mockUser,
},
owner: userMocked,
owner: mockUser,
});

it('When the folder exists, then it is returned', async () => {
Expand All @@ -1432,32 +1433,17 @@ describe('FolderUseCases', () => {

const result = await service.getFolderByUuidAndUser(
mockFolder.uuid,
userMocked,
mockUser,
);

expect(result).toBe(mockFolder);
});

it('When the folder is not owned by the user, then an error is thrown', async () => {
const otherUser = User.build({
...userMocked,
id: userMocked.id + 1,
userId: v4(),
});
jest
.spyOn(folderRepository, 'findByUuidAndUser')
.mockResolvedValueOnce(mockFolder);

await expect(
service.getFolderByUuidAndUser(mockFolder.uuid, otherUser),
).rejects.toThrow(ForbiddenException);
});

it('When the folder is not found, then an error is thrown', async () => {
jest.spyOn(folderRepository, 'findByUuidAndUser').mockResolvedValue(null);

await expect(
service.getFolderByUuidAndUser(mockFolder.uuid, userMocked),
service.getFolderByUuidAndUser(mockFolder.uuid, mockUser),
).rejects.toThrow(NotFoundException);
});
});
Expand Down
4 changes: 0 additions & 4 deletions src/modules/folder/folder.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ export class FolderUseCases {
throw new NotFoundException();
}

if (folder.userId !== user.id) {
throw new ForbiddenException();
}

return folder;
}

Expand Down

0 comments on commit 27e8be8

Please sign in to comment.