Skip to content

Commit

Permalink
fix(transform): Fix transform to handle 0 items
Browse files Browse the repository at this point in the history
  • Loading branch information
James Talton authored and James Talton committed Jul 17, 2019
1 parent 0bb5dc3 commit 55e573f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/utils/promise-transform-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ export class PromiseTransformStream extends Transform {
}

public end(chunk: any, encoding?: any, cb?: () => void): void {
this.endCallback = () => {
if (this.results.length === 0) {
super.end(chunk, encoding, cb)
} else {
this.endCallback = () => {
super.end(chunk, encoding, cb)
}
}
}
}
11 changes: 11 additions & 0 deletions test/mongo-router-transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ function getMockItems(count = 4) {
return mockItems
}

describe(`GET /:database/:collection`, function() {
it(`should work with transform and 0 items in collection`, async function() {
let response = await request.delete(`/${database}/${collection}`)
expect(response.status).toEqual(200)

response = await request.get(`/${database}/${collection}`)
expect(response.status).toEqual(200)
expect(response.data).toEqual([])
})
})

describe(`PUT&GET /:database/:collection`, function() {
it(`should transform items`, async function() {
const mockItems = getMockItems()
Expand Down

0 comments on commit 55e573f

Please sign in to comment.