Skip to content

Commit

Permalink
test: improve folder trash assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanVicens committed Mar 11, 2024
1 parent 2f3aac5 commit b61f9cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

export class FolderRemoteFileSystemMock implements RemoteFileSystem {
private readonly persistMock = jest.fn();
public readonly trashMock = jest.fn();
private readonly trashMock = jest.fn();
public readonly moveMock = jest.fn();
public readonly renameMock = jest.fn();

Expand All @@ -24,7 +24,9 @@ export class FolderRemoteFileSystemMock implements RemoteFileSystem {
}

trash(id: number): Promise<void> {
return this.trashMock(id);
expect(this.trashMock).toBeCalledWith(id);

return this.trashMock();
}

move(folder: Folder): Promise<void> {
Expand All @@ -50,4 +52,15 @@ export class FolderRemoteFileSystemMock implements RemoteFileSystem {
parentId: folder.parentId as number,
} satisfies FolderPersistedDto);
}

shouldTrash(folder: Folder, error?: Error) {
this.trashMock(folder.id);

if (error) {
this.trashMock.mockRejectedValueOnce(error);
return;
}

this.trashMock.mockReturnValue(Promise.resolve());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ describe('Folder deleter', () => {
it('trashes an existing folder', async () => {
const folder = FolderMother.exists();

remote.shouldTrash(folder);

repository.searchByUuidMock.mockResolvedValueOnce(folder);
jest
.spyOn(allParentFoldersStatusIsExists, 'run')
.mockResolvedValueOnce(true);

await SUT.run(folder.uuid);

expect(remote.trashMock).toBeCalledWith(folder.id);
});

it('throws an error when trashing a folder already trashed', async () => {
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('Folder deleter', () => {
jest
.spyOn(allParentFoldersStatusIsExists, 'run')
.mockResolvedValueOnce(true);
remote.trashMock.mockRejectedValue(new Error('Error during the deletion'));
remote.shouldTrash(folder, new Error('Error during the deletion'));

await SUT.run(folder.uuid);

Expand Down

0 comments on commit b61f9cb

Please sign in to comment.