383
383
384
384
} ) ;
385
385
} ) ;
386
+
387
+ describe ( 'Meta Data' , function ( ) {
388
+ var ds ;
389
+ var test = { config : { } } ;
390
+
391
+ beforeEach ( function ( ) {
392
+ ds = new JSData . DS ( ) ;
393
+ var dsHttpAdapter = new DSJsonApiAdapter . JsonApiAdapter ( {
394
+ queryTransform : queryTransform
395
+ } ) ;
396
+ ds . registerAdapter ( 'jsonApi' , dsHttpAdapter , { default : true } ) ;
397
+
398
+ test . config . User = ds . defineResource ( {
399
+ name : 'user' ,
400
+ idAttribute : 'id'
401
+ } ) ;
402
+
403
+ test . jsonApiData = new DSJsonApiAdapter . JsonApi . JsonApiRequest ( ) ;
404
+ test . jsonApiData . WithData (
405
+ new DSJsonApiAdapter . JsonApi . JsonApiData ( 'user' )
406
+ . WithId ( '2' )
407
+ . WithAttribute ( 'author' , 'John' )
408
+ . WithAttribute ( 'age' , 31 ) ) ;
409
+
410
+ test . model = [ { Id : '2' , author : 'John' , age : 31 } ] ; //ISMODEL: true, type: 'testuser'
411
+ } ) ;
412
+
413
+ it ( 'should not serialize meta data' , function ( ) {
414
+ var _this = this ;
415
+
416
+ setTimeout ( function ( ) {
417
+ assert . equal ( 1 , _this . requests . length ) ;
418
+ _this . requests [ 0 ] . respond ( 200 , { 'Content-Type' : 'application/vnd.api+json' } , JSON . stringify ( test . jsonApiData ) ) ;
419
+ } , 30 ) ;
420
+
421
+ return test . config . User . create ( { author : 'John' , age : 32 } ) . then ( function ( data ) {
422
+ var user = test . config . User . get ( 2 ) ;
423
+ var meta = DSJsonApiAdapter . TryGetMetaData ( user ) ;
424
+ assert . isDefined ( user , 'user should be in the store' ) ;
425
+ assert . isDefined ( meta , 'user should have meta data in the store' ) ;
426
+
427
+ setTimeout ( function ( ) {
428
+ assert . equal ( 2 , _this . requests . length , 'should make second request' ) ;
429
+
430
+ var request = JSON . parse ( _this . requests [ 1 ] . requestBody ) ;
431
+ assert . isUndefined ( request . data . attributes [ '$_JSONAPIMETA_' ] , 'should not send meta data' ) ;
432
+
433
+ _this . requests [ 1 ] . respond ( 200 , { 'Content-Type' : 'application/vnd.api+json' } , _this . requests [ 1 ] . requestBody ) ;
434
+ } , 30 ) ;
435
+
436
+ user . name = 'bob' ;
437
+ return test . config . User . save ( user . id ) ;
438
+ } ) ;
439
+ } ) ;
440
+ } ) ;
386
441
} ) ;
0 commit comments