Skip to content

Commit

Permalink
refactor(bucketentries): remove deprecated usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
sg-gs committed Nov 24, 2023
1 parent 45afa67 commit c070314
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 42 deletions.
10 changes: 0 additions & 10 deletions lib/core/bucketEntries/usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ export class BucketEntriesUsecase {
return this.removeFile(fileId);
}

async removeFileAndValidateBucketExists(bucketId: string, fileId: string) {
const bucket = await this.bucketsRepository.findOne({ id: bucketId });

if(!bucket) {
throw new BucketNotFoundError();
}

return this.removeFile(fileId);
}

async removeFile(fileId: string): Promise<void> {
const bucketEntry = await this.bucketEntriesRepository.findOne({ id: fileId });

Expand Down
32 changes: 0 additions & 32 deletions tests/lib/core/bucketentries/usecase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,36 +642,4 @@ describe('BucketEntriesUsecase', function () {
expect(removeFileStub.calledWith(fileId)).toBeTruthy();
});
});

describe('removeFileAndValidateBucketExists()', () => {
it('Should throw an error if bucket is not found', async () => {
try {
const bucket = fixtures.getBucket();
const fileId = 'file-id';

stub(bucketsRepository, 'findOne').resolves(null);

await bucketEntriesUsecase.removeFileAndValidateBucketExists(bucket.id, fileId);
} catch (err) {
expect(err).toBeInstanceOf(BucketNotFoundError);
}
});

it('Should try to remove the file if the bucket exists', async () => {
const user = fixtures.getUser({ id: userEmail });
const bucket = fixtures.getBucket({ user: user.id });
const fileId = 'file-id';

const findBucketStub = stub(bucketsRepository, 'findOne').resolves(bucket);
const removeFileStub = stub(bucketEntriesUsecase, 'removeFile').resolves();

await bucketEntriesUsecase.removeFileAndValidateBucketExists(bucket.id, fileId);

expect(findBucketStub.calledOnce).toBeTruthy();
expect(findBucketStub.calledWith({ id: bucket.id })).toBeTruthy();

expect(removeFileStub.calledOnce).toBeTruthy();
expect(removeFileStub.calledWith(fileId)).toBeTruthy();
});
});
});

0 comments on commit c070314

Please sign in to comment.