mirror of
https://github.com/typicode/json-server.git
synced 2025-07-29 13:14:12 +08:00
Add _expand parameter when retrieving single resource
This commit is contained in:
@ -24,12 +24,17 @@ describe('Server', function () {
|
||||
{id: 3, body: 'photo'}
|
||||
]
|
||||
|
||||
db.users = [
|
||||
{id: 1, username: 'Jim'},
|
||||
{id: 2, username: 'George'}
|
||||
]
|
||||
|
||||
db.comments = [
|
||||
{id: 1, published: true, postId: 1},
|
||||
{id: 2, published: false, postId: 1},
|
||||
{id: 3, published: false, postId: 2},
|
||||
{id: 4, published: false, postId: 2},
|
||||
{id: 5, published: false, postId: 2}
|
||||
{id: 1, published: true, postId: 1, userId: 1},
|
||||
{id: 2, published: false, postId: 1, userId: 2},
|
||||
{id: 3, published: false, postId: 2, userId: 1},
|
||||
{id: 4, published: false, postId: 2, userId: 2},
|
||||
{id: 5, published: false, postId: 2, userId: 1}
|
||||
]
|
||||
|
||||
db.refs = [
|
||||
@ -242,6 +247,31 @@ describe('Server', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('GET /:resource/:id?_expand=', function () {
|
||||
it('should respond with corresponding resource and expanded inner resources', function (done) {
|
||||
var comments = db.comments[0]
|
||||
comments.posts = [db.posts[0]]
|
||||
request(server)
|
||||
.get('/comments/1?_expand=posts')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(comments)
|
||||
.expect(200, done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('GET /:resource/:id?_expand=&_expand=', function () {
|
||||
it('should respond with corresponding resource and expanded inner resources', function (done) {
|
||||
var comments = db.comments[0]
|
||||
comments.posts = [db.posts[0]]
|
||||
comments.users = [db.users[0]]
|
||||
request(server)
|
||||
.get('/comments/1?_expand=posts&_expand=users')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(comments)
|
||||
.expect(200, done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('POST /:resource', function () {
|
||||
it('should respond with json, create a resource and increment id',
|
||||
function (done) {
|
||||
|
Reference in New Issue
Block a user