From 2707104df4e93dcf07bceb4fb2fc2cd8b2454d5c Mon Sep 17 00:00:00 2001 From: Ivan Zaldivar Date: Sun, 10 Apr 2022 09:43:19 -0600 Subject: [PATCH] Fix: Validation when id is empty was implemented. Close #3 --- package.json | 2 +- src/services/file.service.ts | 4 +++- test/file.service.spec.ts | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f0f1bad..3a6ff32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "filesrocket-amazons3", - "version": "0.0.4", + "version": "0.0.5", "description": "Filerocket service to manage files from Amazon Storage S3", "main": "lib/index.js", "types": "lib", diff --git a/src/services/file.service.ts b/src/services/file.service.ts index 07fe627..8b5581a 100644 --- a/src/services/file.service.ts +++ b/src/services/file.service.ts @@ -5,7 +5,7 @@ import { OutputEntity, Query } from 'filesrocket' -import { NotFound } from 'filesrocket/lib/errors' +import { BadRequest, NotFound } from 'filesrocket/lib/errors' import { omitProps } from 'filesrocket/lib/utils' import { ManagedUpload } from 'aws-sdk/clients/s3' @@ -73,6 +73,8 @@ export class FileService extends BaseAmazonRocket implements ServiceMethods { } async get (id: string, query: Query = {}): Promise { + if (!id) throw new BadRequest('Id is empty') + const partialQuery = omitProps(query, ['path']) const Bucket = query.Bucket || this.options.Bucket diff --git a/test/file.service.spec.ts b/test/file.service.spec.ts index 02fa41b..9464069 100644 --- a/test/file.service.spec.ts +++ b/test/file.service.spec.ts @@ -81,6 +81,12 @@ describe('Getting files', () => { .rejects .toThrowError('File does not exist') }) + + test('Get a file when an empty id is sent', async () => { + await expect(findOne('')) + .rejects + .toThrowError('Id is empty') + }) }) describe('Deleting files', () => {