1- var request = require ( 'supertest' )
21var assert = require ( 'assert' )
2+ var _ = require ( 'lodash' )
3+ var request = require ( 'supertest' )
34var jsonServer = require ( '../../src/server' )
45
56/* global beforeEach, describe, it */
@@ -38,7 +39,7 @@ describe('Server', function () {
3839 ]
3940
4041 db . refs = [
41- { id : 'abcd-1234' , url : 'http://example.com/' , postId : 1 }
42+ { id : 'abcd-1234' , url : 'http://example.com/' , postId : 1 , userId : 1 }
4243 ]
4344
4445 db . deep = [
@@ -238,8 +239,36 @@ describe('Server', function () {
238239 } )
239240 } )
240241
242+ describe ( 'GET /:resource?_embed=' , function ( ) {
243+ it ( 'should respond with corresponding resources and embedded resources' , function ( done ) {
244+ var posts = _ . cloneDeep ( db . posts )
245+ posts [ 0 ] . comments = [ db . comments [ 0 ] , db . comments [ 1 ] ]
246+ posts [ 1 ] . comments = [ db . comments [ 2 ] , db . comments [ 3 ] , db . comments [ 4 ] ]
247+ request ( server )
248+ . get ( '/posts?_embed=comments' )
249+ . expect ( 'Content-Type' , / j s o n / )
250+ . expect ( posts )
251+ . expect ( 200 , done )
252+ } )
253+ } )
254+
255+ describe ( 'GET /:resource?_embed&_embed=' , function ( ) {
256+ it ( 'should respond with corresponding resources and embedded resources' , function ( done ) {
257+ var posts = _ . cloneDeep ( db . posts )
258+ posts [ 0 ] . comments = [ db . comments [ 0 ] , db . comments [ 1 ] ]
259+ posts [ 0 ] . refs = [ db . refs [ 0 ] ]
260+ posts [ 1 ] . comments = [ db . comments [ 2 ] , db . comments [ 3 ] , db . comments [ 4 ] ]
261+ posts [ 1 ] . refs = [ ]
262+ request ( server )
263+ . get ( '/posts?_embed=comments&_embed=refs' )
264+ . expect ( 'Content-Type' , / j s o n / )
265+ . expect ( posts )
266+ . expect ( 200 , done )
267+ } )
268+ } )
269+
241270 describe ( 'GET /:resource/:id?_embed=' , function ( ) {
242- it ( 'should respond with corresponding resource and embedded other resource ' , function ( done ) {
271+ it ( 'should respond with corresponding resources and embedded resources ' , function ( done ) {
243272 var posts = db . posts [ 0 ]
244273 posts . comments = [ db . comments [ 0 ] , db . comments [ 1 ] ]
245274 request ( server )
@@ -251,7 +280,7 @@ describe('Server', function () {
251280 } )
252281
253282 describe ( 'GET /:resource/:id?_embed=&_embed=' , function ( ) {
254- it ( 'should respond with corresponding resource and embedded other resources' , function ( done ) {
283+ it ( 'should respond with corresponding resource and embedded resources' , function ( done ) {
255284 var posts = db . posts [ 0 ]
256285 posts . comments = [ db . comments [ 0 ] , db . comments [ 1 ] ]
257286 posts . refs = [ db . refs [ 0 ] ]
@@ -263,6 +292,18 @@ describe('Server', function () {
263292 } )
264293 } )
265294
295+ describe ( 'GET /:resource?_expand=' , function ( ) {
296+ it ( 'should respond with corresponding resource and expanded inner resources' , function ( done ) {
297+ var refs = _ . cloneDeep ( db . refs )
298+ refs [ 0 ] . post = db . posts [ 0 ]
299+ request ( server )
300+ . get ( '/refs?_expand=post' )
301+ . expect ( 'Content-Type' , / j s o n / )
302+ . expect ( refs )
303+ . expect ( 200 , done )
304+ } )
305+ } )
306+
266307 describe ( 'GET /:resource/:id?_expand=' , function ( ) {
267308 it ( 'should respond with corresponding resource and expanded inner resources' , function ( done ) {
268309 var comments = db . comments [ 0 ]
@@ -275,6 +316,19 @@ describe('Server', function () {
275316 } )
276317 } )
277318
319+ describe ( 'GET /:resource?_expand=&_expand' , function ( ) {
320+ it ( 'should respond with corresponding resource and expanded inner resources' , function ( done ) {
321+ var refs = _ . cloneDeep ( db . refs )
322+ refs [ 0 ] . post = db . posts [ 0 ]
323+ refs [ 0 ] . user = db . users [ 0 ]
324+ request ( server )
325+ . get ( '/refs?_expand=post&_expand=user' )
326+ . expect ( 'Content-Type' , / j s o n / )
327+ . expect ( refs )
328+ . expect ( 200 , done )
329+ } )
330+ } )
331+
278332 describe ( 'GET /:resource/:id?_expand=&_expand=' , function ( ) {
279333 it ( 'should respond with corresponding resource and expanded inner resources' , function ( done ) {
280334 var comments = db . comments [ 0 ]
0 commit comments