3
3
var request = require ( 'supertest' )
4
4
var loopback = require ( 'loopback' )
5
5
var expect = require ( 'chai' ) . expect
6
- var query = require ( './util/query' )
7
6
var JSONAPIComponent = require ( '../' )
8
7
var app
9
8
var Post
@@ -54,7 +53,7 @@ describe('loopback json api component create method', function () {
54
53
)
55
54
it (
56
55
'POST /models should have the JSON API Content-Type header set on response' ,
57
- function ( done ) {
56
+ function ( ) {
58
57
var data = {
59
58
data : {
60
59
type : 'posts' ,
@@ -65,32 +64,24 @@ describe('loopback json api component create method', function () {
65
64
}
66
65
}
67
66
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
+ } )
94
85
}
95
86
)
96
87
0 commit comments