Commit edbeb9e 1 parent 6b39f3d commit edbeb9e Copy full SHA for edbeb9e
File tree 2 files changed +21
-8
lines changed
2 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -135,25 +135,31 @@ define([
135
135
headers : headers
136
136
} ) ;
137
137
var collection = this ;
138
+ var parsedResponse = response . then ( function ( response ) {
139
+ return collection . parse ( response ) ;
140
+ } ) ;
138
141
return {
139
- data : response . then ( function ( response ) {
140
- var results = collection . parse ( response ) ;
142
+ data : parsedResponse . then ( function ( data ) {
141
143
// support items in the results
142
- results = results . items || results ;
144
+ var results = data . items || data ;
143
145
for ( var i = 0 , l = results . length ; i < l ; i ++ ) {
144
146
results [ i ] = collection . _restore ( results [ i ] , true ) ;
145
147
}
146
148
return results ;
147
149
} ) ,
148
- total : response . response . then ( function ( response ) {
149
- var total = response . data . total ;
150
+ total : parsedResponse . then ( function ( data ) {
151
+ // check for a total property
152
+ var total = data . total ;
150
153
if ( total > - 1 ) {
151
154
// if we have a valid positive number from the data,
152
155
// we can use that
153
156
return total ;
154
157
}
155
- var range = response . getHeader ( 'Content-Range' ) ;
156
- return range && ( range = range . match ( / \/ ( .* ) / ) ) && + range [ 1 ] ;
158
+ // else use headers
159
+ return response . response . then ( function ( response ) {
160
+ var range = response . getHeader ( 'Content-Range' ) ;
161
+ return range && ( range = range . match ( / \/ ( .* ) / ) ) && + range [ 1 ] ;
162
+ } ) ;
157
163
} ) ,
158
164
response : response . response
159
165
} ;
Original file line number Diff line number Diff line change @@ -47,9 +47,16 @@ define([
47
47
expected = rangeArgs ;
48
48
results = collection . fetch ( ) ;
49
49
} else {
50
+ mockRequest . setResponseHeaders ( {
51
+ 'Content-Range' : rangeArgs . start + '-' + rangeArgs . end + '/' + expectedResults . length
52
+ } ) ;
50
53
results = collection . fetchRange ( rangeArgs ) ;
54
+ results = results . totalLength . then ( function ( totalLength ) {
55
+ assert . strictEqual ( totalLength , expectedResults . length ) ;
56
+ return results ;
57
+ } ) ;
51
58
}
52
- return when ( results ) . then ( function ( results ) {
59
+ return results . then ( function ( results ) {
53
60
expected . headers && mockRequest . assertRequestHeaders ( expected . headers ) ;
54
61
expected . queryParams && mockRequest . assertQueryParams ( expected . queryParams ) ;
55
62
You can’t perform that action at this time.
0 commit comments