Skip to content

Commit

Permalink
Fix: Validation when id is empty was implemented. Close #3
Browse files Browse the repository at this point in the history
  • Loading branch information
thebug404 committed Apr 10, 2022
1 parent 7053f03 commit 2707104
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/services/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -73,6 +73,8 @@ export class FileService extends BaseAmazonRocket implements ServiceMethods {
}

async get (id: string, query: Query = {}): Promise<OutputEntity> {
if (!id) throw new BadRequest('Id is empty')

const partialQuery = omitProps(query, ['path'])

const Bucket = query.Bucket || this.options.Bucket
Expand Down
6 changes: 6 additions & 0 deletions test/file.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 2707104

Please sign in to comment.