mirror of
https://github.com/typicode/json-server.git
synced 2025-08-03 04:12:22 +08:00
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:
@ -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')
|
||||
|
Reference in New Issue
Block a user