@@ -7,6 +7,12 @@ after(function () {
77 fetchMock . restore ( ) ;
88} ) ;
99
10+ let resultData = function ( promise ) {
11+ return promise . then ( function ( proxyObject ) {
12+ return proxyObject . data
13+ } )
14+ }
15+
1016describe ( 'Model finders' , function ( ) {
1117 describe ( '#find()' , function ( ) {
1218 before ( function ( ) {
@@ -22,13 +28,13 @@ describe('Model finders', function() {
2228 } ) ;
2329
2430 it ( 'returns a promise that resolves the correct instance' , function ( ) {
25- return expect ( Person . find ( 1 ) ) . to . eventually
31+ return expect ( resultData ( Person . find ( 1 ) ) ) . to . eventually
2632 . be . instanceof ( Person ) . and
2733 . have . property ( 'id' , '1' ) ;
2834 } ) ;
2935
3036 it ( 'assigns attributes correctly' , function ( ) {
31- return expect ( Person . find ( 1 ) ) . to . eventually
37+ return expect ( resultData ( Person . find ( 1 ) ) ) . to . eventually
3238 . have . property ( 'name' , 'John' )
3339 } ) ;
3440
@@ -44,7 +50,7 @@ describe('Model finders', function() {
4450 } ) ;
4551
4652 it ( 'resolves to the correct class' , function ( ) {
47- return expect ( Person . find ( 1 ) ) . to . eventually
53+ return expect ( resultData ( Person . find ( 1 ) ) ) . to . eventually
4854 . be . instanceof ( Author ) ;
4955 } ) ;
5056 } ) ;
@@ -71,7 +77,8 @@ describe('Model finders', function() {
7177 } ) ;
7278
7379 describe ( '#all()' , function ( ) {
74- before ( function ( ) {
80+ beforeEach ( function ( ) {
81+ fetchMock . restore ( ) ;
7582 fetchMock . get ( 'http://example.com/api/v1/people' , {
7683 data : [
7784 { id : '1' , type : 'people' }
@@ -80,10 +87,33 @@ describe('Model finders', function() {
8087 } ) ;
8188
8289 it ( 'returns a promise that resolves the correct instances' , function ( ) {
83- return expect ( Person . all ( ) ) . to . eventually
90+ return expect ( resultData ( Person . all ( ) ) ) . to . eventually
8491 . all . be . instanceof ( Person )
8592 . all . have . property ( 'id' , '1' )
8693 } ) ;
94+
95+ describe ( 'response includes a meta payload' , function ( ) {
96+ beforeEach ( function ( ) {
97+ fetchMock . restore ( ) ;
98+ fetchMock . get ( 'http://example.com/api/v1/people' , {
99+ data : [
100+ { id : '1' , type : 'people' }
101+ ] ,
102+ meta : {
103+ stats : {
104+ total : {
105+ count : 45
106+ } ,
107+ }
108+ }
109+ } ) ;
110+ } ) ;
111+
112+ it ( 'includes meta payload in the resulting collection' , function ( ) {
113+ return expect ( Person . all ( ) ) . to . eventually
114+ . have . deep . property ( 'meta.stats.total.count' , 45 )
115+ } ) ;
116+ } ) ;
87117 } ) ;
88118
89119 describe ( '#page' , function ( ) {
@@ -96,25 +126,24 @@ describe('Model finders', function() {
96126 } ) ;
97127
98128 it ( 'queries correctly' , function ( ) {
99- return expect ( Person . page ( 2 ) . all ( ) ) . to . eventually
129+ return expect ( resultData ( Person . page ( 2 ) . all ( ) ) ) . to . eventually
100130 . all . be . instanceof ( Person )
101131 . all . have . property ( 'id' , '2' )
102132 } ) ;
103133 } ) ;
104134
105135 describe ( '#per' , function ( ) {
106136 before ( function ( ) {
107- fetchMock . get ( 'http://example.com/api/v1/people?page[size]=10 ' , {
137+ fetchMock . get ( 'http://example.com/api/v1/people?page[size]=2 ' , {
108138 data : [
109- { id : '2 ' , type : 'people' }
139+ { id : '1 ' , type : 'people' }
110140 ]
111141 } ) ;
112142 } ) ;
113143
114144 it ( 'queries correctly' , function ( ) {
115- return expect ( Person . page ( 2 ) . all ( ) ) . to . eventually
145+ return expect ( resultData ( Person . per ( 2 ) . all ( ) ) ) . to . eventually
116146 . all . be . instanceof ( Person )
117- . all . have . property ( 'id' , '2' )
118147 } ) ;
119148 } ) ;
120149
@@ -128,7 +157,7 @@ describe('Model finders', function() {
128157 } ) ;
129158
130159 it ( 'queries correctly' , function ( ) {
131- return expect ( Person . order ( 'foo' ) . order ( { bar : 'desc' } ) . all ( ) ) . to . eventually
160+ return expect ( resultData ( Person . order ( 'foo' ) . order ( { bar : 'desc' } ) . all ( ) ) ) . to . eventually
132161 . all . be . instanceof ( Person )
133162 . all . have . property ( 'id' , '2' )
134163 } ) ;
@@ -144,7 +173,7 @@ describe('Model finders', function() {
144173 } ) ;
145174
146175 it ( 'queries correctly' , function ( ) {
147- return expect ( Person . where ( { id : 2 } ) . where ( { a : 'b' } ) . all ( ) ) . to . eventually
176+ return expect ( resultData ( Person . where ( { id : 2 } ) . where ( { a : 'b' } ) . all ( ) ) ) . to . eventually
148177 . all . be . instanceof ( Person )
149178 . all . have . property ( 'id' , '2' )
150179 } ) ;
@@ -160,7 +189,7 @@ describe('Model finders', function() {
160189 } ) ;
161190
162191 it ( 'queries correctly' , function ( ) {
163- return expect ( Person . select ( { people : [ 'name' , 'age' ] } ) . all ( ) ) . to . eventually
192+ return expect ( resultData ( Person . select ( { people : [ 'name' , 'age' ] } ) . all ( ) ) ) . to . eventually
164193 . all . be . instanceof ( Person )
165194 . all . have . property ( 'id' , '2' )
166195 } ) ;
@@ -176,7 +205,7 @@ describe('Model finders', function() {
176205 } ) ;
177206
178207 it ( 'queries correctly' , function ( ) {
179- return expect ( Person . selectExtra ( { people : [ 'net_worth' , 'best_friend' ] } ) . all ( ) ) . to . eventually
208+ return expect ( resultData ( Person . selectExtra ( { people : [ 'net_worth' , 'best_friend' ] } ) . all ( ) ) ) . to . eventually
180209 . all . be . instanceof ( Person )
181210 . all . have . property ( 'id' , '2' )
182211 } ) ;
@@ -195,7 +224,7 @@ describe('Model finders', function() {
195224 } ) ;
196225
197226 it ( 'queries correctly' , function ( ) {
198- return expect ( Person . includes ( { a : [ 'b' , { c : 'd' } ] } ) . all ( ) ) . to . eventually
227+ return expect ( resultData ( Person . includes ( { a : [ 'b' , { c : 'd' } ] } ) . all ( ) ) ) . to . eventually
199228 . all . be . instanceof ( Person )
200229 . all . have . property ( 'id' , '2' )
201230 } ) ;
0 commit comments