@@ -10,92 +10,105 @@ var _appAgent2 = _interopRequireDefault(_appAgent);
10
10
11
11
var _fixturesCreation = require ( "../fixtures/creation" ) ;
12
12
13
- describe ( "" , function ( ) {
14
- _appAgent2 [ "default" ] . then ( function ( Agent ) {
15
- Agent . request ( "POST" , "/organizations" ) . type ( "application/vnd.api+json" ) . send ( { "data" : _fixturesCreation . VALID_ORG_RESOURCE_NO_ID_EXTRA_MEMBER , "extra" : false } ) . promise ( ) . then ( function ( res ) {
16
- var createdResource = res . body . data ;
17
-
18
- describe ( "Creating a Valid Resource (With an Extra Member)" , function ( ) {
19
- describe ( "HTTP" , function ( ) {
20
- it ( "should return 201" , function ( ) {
21
- ( 0 , _chai . expect ) ( res . status ) . to . equal ( 201 ) ;
22
- } ) ;
23
-
24
- it ( "should include a valid Location header" , function ( ) {
25
- ( 0 , _chai . expect ) ( res . headers . location ) . to . match ( / \/ o r g a n i z a t i o n s \/ [ a - z 0 - 9 ] + / ) ;
26
- ( 0 , _chai . expect ) ( createdResource . links . self ) . to . equal ( res . headers . location ) ;
27
- } ) ;
13
+ describe ( "Creating Resources " , function ( ) {
14
+ var Agent = undefined ;
15
+
16
+ describe ( "Creating a Valid Resource (With an Extra Member)" , function ( ) {
17
+ var createdResource = undefined ,
18
+ createdId = undefined ,
19
+ res = undefined ;
20
+ before ( function ( done ) {
21
+ _appAgent2 [ "default" ] . then ( function ( A ) {
22
+ Agent = A ;
23
+ Agent . request ( "POST" , "/organizations" ) . type ( "application/vnd.api+json" ) . send ( { "data" : _fixturesCreation . VALID_ORG_RESOURCE_NO_ID_EXTRA_MEMBER , "extra" : false } ) . promise ( ) . then ( function ( response ) {
24
+ res = response ;
25
+ createdResource = res . body . data ;
26
+ createdId = res . body . data . id ;
27
+ done ( ) ;
28
28
} ) ;
29
+ } ) [ "catch" ] ( done ) ;
30
+ } ) ;
29
31
30
- describe ( "Document Structure" , function ( ) {
31
- // "A JSON object MUST be at the root of every
32
- // JSON API request and response containing data."
33
- it ( "should have an object/document at the top level" , function ( ) {
34
- ( 0 , _chai . expect ) ( res . body ) . to . be . an ( "object" ) ;
35
- } ) ;
36
-
37
- it ( "should ignore extra document object members" , function ( ) {
38
- ( 0 , _chai . expect ) ( res . status ) . to . be . within ( 200 , 299 ) ;
39
- ( 0 , _chai . expect ) ( res . body . extra ) . to . be . undefined ;
40
- } ) ;
41
-
42
- describe ( "Links" , function ( ) { } ) ;
43
-
44
- describe ( "Transforms" , function ( ) {
45
- describe ( "beforeSave" , function ( ) {
46
- it ( "should execute beforeSave hook" , function ( ) {
47
- ( 0 , _chai . expect ) ( createdResource . attributes . description ) . to . equal ( "Added a description in beforeSave" ) ;
48
- } ) ;
49
-
50
- it ( "should allow beforeSave to return a Promise" , function ( done ) {
51
- Agent . request ( "POST" , "/schools" ) . type ( "application/vnd.api+json" ) . send ( { "data" : _fixturesCreation . VALID_SCHOOL_RESOURCE_NO_ID } ) . promise ( ) . then ( function ( res2 ) {
52
- ( 0 , _chai . expect ) ( res2 . body . data . attributes . description ) . to . equal ( "Modified in a Promise" ) ;
53
- done ( ) ;
54
- } , done ) [ "catch" ] ( done ) ;
55
- } ) ;
56
- } ) ;
57
- } ) ;
58
-
59
- describe ( "The Created Resource" , function ( ) {
60
- it ( "should return the created resource" , function ( ) {
61
- ( 0 , _chai . expect ) ( createdResource ) . to . be . an ( "object" ) ;
62
- ( 0 , _chai . expect ) ( createdResource . type ) . to . equal ( "organizations" ) ;
63
- ( 0 , _chai . expect ) ( createdResource . attributes ) . to . be . an ( "object" ) ;
64
- ( 0 , _chai . expect ) ( createdResource . relationships ) . to . be . an ( "object" ) ;
65
- ( 0 , _chai . expect ) ( createdResource . relationships . liaisons ) . to . be . an ( "object" ) ;
66
- } ) ;
67
-
68
- it ( "should ignore extra resource object members" , function ( ) {
69
- ( 0 , _chai . expect ) ( res . body . data . extraMember ) . to . be . undefined ;
70
- ( 0 , _chai . expect ) ( res . body . data . attributes . extraMember ) . to . be . undefined ;
71
- } ) ;
72
- } ) ;
73
- } ) ;
32
+ describe ( "HTTP" , function ( ) {
33
+ it ( "should return 201" , function ( ) {
34
+ ( 0 , _chai . expect ) ( res . status ) . to . equal ( 201 ) ;
35
+ } ) ;
36
+
37
+ it ( "should include a valid Location header" , function ( ) {
38
+ ( 0 , _chai . expect ) ( res . headers . location ) . to . match ( / \/ o r g a n i z a t i o n s \/ [ a - z 0 - 9 ] + / ) ;
39
+ ( 0 , _chai . expect ) ( createdResource . links . self ) . to . equal ( res . headers . location ) ;
40
+ } ) ;
41
+ } ) ;
42
+
43
+ describe ( "Document Structure" , function ( ) {
44
+ // "A JSON object MUST be at the root of every
45
+ // JSON API request and response containing data."
46
+ it ( "should have an object/document at the top level" , function ( ) {
47
+ ( 0 , _chai . expect ) ( res . body ) . to . be . an ( "object" ) ;
74
48
} ) ;
75
- } ) . done ( ) ;
76
- } ) . done ( ) ;
77
- } ) ;
78
49
79
- describe ( "" , function ( ) {
80
- _appAgent2 [ "default" ] . then ( function ( Agent ) {
81
- Agent . request ( "POST" , "/organizations" ) . type ( "application/vnd.api+json" ) . send ( { "data" : _fixturesCreation . ORG_RESOURCE_CLIENT_ID } ) . promise ( ) . then ( function ( ) {
82
- throw new Error ( "Should not run!" ) ;
83
- } , function ( err ) {
84
- describe ( "Creating a Resource With A Client-Id" , function ( ) {
85
- describe ( "HTTP" , function ( ) {
86
- it ( "should return 403" , function ( ) {
87
- ( 0 , _chai . expect ) ( err . response . status ) . to . equal ( 403 ) ;
88
- } ) ;
50
+ it ( "should ignore extra document object members" , function ( ) {
51
+ ( 0 , _chai . expect ) ( res . status ) . to . be . within ( 200 , 299 ) ;
52
+ ( 0 , _chai . expect ) ( res . body . extra ) . to . be . undefined ;
53
+ } ) ;
54
+ } ) ;
55
+
56
+ describe ( "Links" , function ( ) { } ) ;
57
+
58
+ describe ( "Transforms" , function ( ) {
59
+ describe ( "beforeSave" , function ( ) {
60
+ it ( "should execute beforeSave hook" , function ( ) {
61
+ ( 0 , _chai . expect ) ( createdResource . attributes . description ) . to . equal ( "Added a description in beforeSave" ) ;
89
62
} ) ;
90
63
91
- describe ( "Document Structure" , function ( ) {
92
- it ( "should contain an error" , function ( ) {
93
- ( 0 , _chai . expect ) ( err . response . body . errors ) . to . be . an ( "array" ) ;
94
- } ) ;
64
+ it ( "should allow beforeSave to return a Promise" , function ( done ) {
65
+ Agent . request ( "POST" , "/schools" ) . type ( "application/vnd.api+json" ) . send ( { "data" : _fixturesCreation . VALID_SCHOOL_RESOURCE_NO_ID } ) . promise ( ) . then ( function ( response ) {
66
+ ( 0 , _chai . expect ) ( response . body . data . attributes . description ) . to . equal ( "Modified in a Promise" ) ;
67
+ done ( ) ;
68
+ } , done ) [ "catch" ] ( done ) ;
95
69
} ) ;
96
70
} ) ;
97
- } ) . done ( ) ;
98
- } ) . done ( ) ;
71
+ } ) ;
72
+
73
+ describe ( "The Created Resource" , function ( ) {
74
+ it ( "should be returned in the body" , function ( ) {
75
+ ( 0 , _chai . expect ) ( createdResource ) . to . be . an ( "object" ) ;
76
+ ( 0 , _chai . expect ) ( createdResource . type ) . to . equal ( "organizations" ) ;
77
+ ( 0 , _chai . expect ) ( createdResource . attributes ) . to . be . an ( "object" ) ;
78
+ ( 0 , _chai . expect ) ( createdResource . relationships ) . to . be . an ( "object" ) ;
79
+ ( 0 , _chai . expect ) ( createdResource . relationships . liaisons ) . to . be . an ( "object" ) ;
80
+ } ) ;
81
+
82
+ it ( "should ignore extra resource object members" , function ( ) {
83
+ ( 0 , _chai . expect ) ( res . body . data . extraMember ) . to . be . undefined ;
84
+ ( 0 , _chai . expect ) ( res . body . data . attributes . extraMember ) . to . be . undefined ;
85
+ } ) ;
86
+ } ) ;
87
+ } ) ;
88
+
89
+ describe ( "Creating a Resource With A Client-Id" , function ( ) {
90
+ var err = undefined ;
91
+ before ( function ( done ) {
92
+ Agent . request ( "POST" , "/organizations" ) . type ( "application/vnd.api+json" ) . send ( { "data" : _fixturesCreation . ORG_RESOURCE_CLIENT_ID } ) . promise ( ) . then ( function ( ) {
93
+ return done ( "Should not run!" ) ;
94
+ } , function ( error ) {
95
+ err = error ;
96
+ done ( ) ;
97
+ } ) ;
98
+ } ) ;
99
+
100
+ describe ( "HTTP" , function ( ) {
101
+ it ( "should return 403" , function ( ) {
102
+ ( 0 , _chai . expect ) ( err . response . status ) . to . equal ( 403 ) ;
103
+ } ) ;
104
+ } ) ;
105
+
106
+ describe ( "Document Structure" , function ( ) {
107
+ it ( "should contain an error" , function ( ) {
108
+ ( 0 , _chai . expect ) ( err . response . body . errors ) . to . be . an ( "array" ) ;
109
+ } ) ;
110
+ } ) ;
111
+ } ) ;
99
112
} ) ;
100
113
101
114
// "[S]erver implementations MUST ignore
0 commit comments