@@ -142,7 +142,12 @@ _beforeEach.givenAnAnonymousToken = function(attrs, optionalHandler) {
142
142
_beforeEach . givenModel ( 'accessToken' , { id : '$anonymous' } , optionalHandler ) ;
143
143
}
144
144
145
- _describe . whenCalledRemotely = function ( verb , url , cb ) {
145
+ _describe . whenCalledRemotely = function ( verb , url , data , cb ) {
146
+ if ( cb == undefined ) {
147
+ cb = data ;
148
+ data = null ;
149
+ }
150
+
146
151
var urlStr = url ;
147
152
if ( typeof url === 'function' ) {
148
153
urlStr = '/<dynamic>' ;
@@ -160,17 +165,23 @@ _describe.whenCalledRemotely = function(verb, url, cb) {
160
165
if ( methodForVerb === 'delete' ) methodForVerb = 'del' ;
161
166
162
167
this . http = this . request [ methodForVerb ] ( this . url ) ;
163
- this . url = undefined ;
168
+ delete this . url ;
164
169
this . http . set ( 'Accept' , 'application/json' ) ;
165
170
if ( this . loggedInAccessToken ) {
166
171
this . http . set ( 'authorization' , this . loggedInAccessToken . id ) ;
167
172
}
173
+ if ( data ) {
174
+ var payload = data ;
175
+ if ( typeof data === 'function' )
176
+ payload = data . call ( this ) ;
177
+ this . http . send ( payload ) ;
178
+ }
168
179
this . req = this . http . req ;
169
180
var test = this ;
170
181
this . http . end ( function ( err ) {
171
182
test . req = test . http . req ;
172
183
test . res = test . http . res ;
173
- test . url = undefined ;
184
+ delete test . url ;
174
185
cb ( ) ;
175
186
} ) ;
176
187
} ) ;
@@ -186,40 +197,43 @@ _describe.whenLoggedInAsUser = function(credentials, cb) {
186
197
} ) ;
187
198
}
188
199
189
- _describe . whenCalledByUser = function ( credentials , verb , url , cb ) {
200
+ _describe . whenCalledByUser = function ( credentials , verb , url , data , cb ) {
190
201
describe ( 'when called by logged in user' , function ( ) {
191
202
_beforeEach . givenLoggedInUser ( credentials ) ;
192
- _describe . whenCalledRemotely ( verb , url , cb ) ;
203
+ _describe . whenCalledRemotely ( verb , url , data , cb ) ;
193
204
} ) ;
194
205
}
195
206
196
- _describe . whenCalledAnonymously = function ( verb , url , cb ) {
207
+ _describe . whenCalledAnonymously = function ( verb , url , data , cb ) {
197
208
describe ( 'when called anonymously' , function ( ) {
198
209
_beforeEach . givenAnAnonymousToken ( ) ;
199
- _describe . whenCalledRemotely ( verb , url , cb ) ;
210
+ _describe . whenCalledRemotely ( verb , url , data , cb ) ;
200
211
} ) ;
201
212
}
202
213
203
- _describe . whenCalledUnauthenticated = function ( verb , url , cb ) {
214
+ _describe . whenCalledUnauthenticated = function ( verb , url , data , cb ) {
204
215
describe ( 'when called with unauthenticated token' , function ( ) {
205
216
_beforeEach . givenAnAnonymousToken ( ) ;
206
- _describe . whenCalledRemotely ( verb , url , cb ) ;
217
+ _describe . whenCalledRemotely ( verb , url , data , cb ) ;
207
218
} ) ;
208
219
}
209
220
210
221
_it . shouldBeAllowed = function ( ) {
211
222
it ( 'should be allowed' , function ( ) {
212
223
assert ( this . req ) ;
213
224
assert ( this . res ) ;
214
- assert . notEqual ( this . res . statusCode , 401 ) ;
225
+ // expect success - status 2xx or 3xx
226
+ expect ( this . res . statusCode ) . to . be . within ( 100 , 399 ) ;
215
227
} ) ;
216
228
}
217
229
218
230
_it . shouldBeDenied = function ( ) {
219
231
it ( 'should not be allowed' , function ( ) {
220
232
assert ( this . res ) ;
221
- var status = this . res . statusCode ;
222
- assert ( status === 401 || status === 404 ) ;
233
+ var expectedStatus = this . aclErrorStatus ||
234
+ this . app && this . app . get ( 'aclErrorStatus' ) ||
235
+ 401 ;
236
+ expect ( this . res . statusCode ) . to . equal ( expectedStatus ) ;
223
237
} ) ;
224
238
}
225
239
@@ -231,8 +245,8 @@ _it.shouldNotBeFound = function() {
231
245
}
232
246
233
247
_it . shouldBeAllowedWhenCalledAnonymously =
234
- function ( verb , url ) {
235
- _describe . whenCalledAnonymously ( verb , url , function ( ) {
248
+ function ( verb , url , data ) {
249
+ _describe . whenCalledAnonymously ( verb , url , data , function ( ) {
236
250
_it . shouldBeAllowed ( ) ;
237
251
} ) ;
238
252
}
@@ -245,8 +259,8 @@ function(verb, url) {
245
259
}
246
260
247
261
_it . shouldBeAllowedWhenCalledUnauthenticated =
248
- function ( verb , url ) {
249
- _describe . whenCalledUnauthenticated ( verb , url , function ( ) {
262
+ function ( verb , url , data ) {
263
+ _describe . whenCalledUnauthenticated ( verb , url , data , function ( ) {
250
264
_it . shouldBeAllowed ( ) ;
251
265
} ) ;
252
266
}
@@ -259,8 +273,8 @@ function(verb, url) {
259
273
}
260
274
261
275
_it . shouldBeAllowedWhenCalledByUser =
262
- function ( credentials , verb , url ) {
263
- _describe . whenCalledByUser ( credentials , verb , url , function ( ) {
276
+ function ( credentials , verb , url , data ) {
277
+ _describe . whenCalledByUser ( credentials , verb , url , data , function ( ) {
264
278
_it . shouldBeAllowed ( ) ;
265
279
} ) ;
266
280
}
0 commit comments