33var request = require ( 'supertest' )
44var loopback = require ( 'loopback' )
55var expect = require ( 'chai' ) . expect
6- var query = require ( './util/query' )
76var JSONAPIComponent = require ( '../' )
87var app
98var Post
@@ -54,7 +53,7 @@ describe('loopback json api component create method', function () {
5453 )
5554 it (
5655 'POST /models should have the JSON API Content-Type header set on response' ,
57- function ( done ) {
56+ function ( ) {
5857 var data = {
5958 data : {
6059 type : 'posts' ,
@@ -65,32 +64,24 @@ describe('loopback json api component create method', function () {
6564 }
6665 }
6766
68- var options = {
69- headers : {
70- Accept : 'application/vnd.api+json' ,
71- 'Content-Type' : 'application/vnd.api+json'
72- }
73- }
74-
75- // use http module via util to make this post to check headers are working since
76- // superagent/supertest breaks when trying to use JSON API Content-Type header
77- // waiting on a fix
78- // see https://github.com/visionmedia/superagent/issues/753
79- query ( app ) . post ( '/posts' , data , options , function ( err , res ) {
80- expect ( err ) . to . equal ( null )
81- expect ( res . headers [ 'content-type' ] ) . to . match (
82- / a p p l i c a t i o n \/ v n d \. a p i \+ j s o n /
83- )
84- expect ( res . statusCode ) . to . equal ( 201 )
85- expect ( res . body ) . to . have . all . keys ( 'data' )
86- expect ( res . body . data ) . to . have . all . keys (
87- 'type' ,
88- 'id' ,
89- 'links' ,
90- 'attributes'
91- )
92- done ( )
93- } )
67+ return request ( app )
68+ . post ( '/posts' )
69+ . send ( data )
70+ . set ( 'accept' , 'application/vnd.api+json' )
71+ . set ( 'content-type' , 'application/vnd.api+json' )
72+ . then ( res => {
73+ expect ( res . headers [ 'content-type' ] ) . to . match (
74+ / a p p l i c a t i o n \/ v n d \. a p i \+ j s o n /
75+ )
76+ expect ( res . statusCode ) . to . equal ( 201 )
77+ expect ( res . body ) . to . have . all . keys ( 'data' )
78+ expect ( res . body . data ) . to . have . all . keys (
79+ 'type' ,
80+ 'id' ,
81+ 'links' ,
82+ 'attributes'
83+ )
84+ } )
9485 }
9586 )
9687
0 commit comments