update req.query when rewrite without params (#432)

* update req.query when rewrite without params #431

* add tests for rewrite rules with query and without paramas for PR #432

* [typo] add tests for rewrite rules with query and without paramas for PR #432
This commit is contained in:
Ahmed Ayoub
2016-12-08 22:53:16 +01:00
committed by typicode
parent 7c402a8556
commit 202a416098
2 changed files with 17 additions and 6 deletions

View File

@ -78,7 +78,9 @@ describe('Server', () => {
server.use(jsonServer.rewriter({
'/api/': '/',
'/blog/posts/:id/show': '/posts/:id',
'/comments/special/:userId-:body': '/comments/?userId=:userId&body=:body'
'/comments/special/:userId-:body': '/comments/?userId=:userId&body=:body',
'/firstpostwithcomments': '/posts/1?_embed=comments'
}))
server.use(router)
})
@ -686,6 +688,15 @@ describe('Server', () => {
.end(done)
})
it('should rewrite using query without params', function (done) {
const expectedPost = _.cloneDeep(db.posts[0])
expectedPost.comments = [ db.comments[0], db.comments[1] ]
request(server)
.get('/firstpostwithcomments')
.expect(expectedPost)
.end(done)
})
it('should rewrite using params and query', function (done) {
request(server)
.get('/comments/special/1-quux')