Add _expand parameter when retrieving single resource

This commit is contained in:
Eric Adams
2015-06-19 12:39:55 -04:00
parent 682b1bca14
commit f8cd38564a
3 changed files with 56 additions and 5 deletions

View File

@ -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) {