File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ export const Comments = {
2+ data : [
3+ {
4+ id : 1 ,
5+ post_id : 1 ,
6+ someId : 'ma018-9ha12' ,
7+ text : 'Hello' ,
8+ replies : {
9+ data : [
10+ {
11+ id : 3 ,
12+ comment_id : 1 ,
13+ someId : 'ma020-9ha15' ,
14+ text : 'Hello' ,
15+ }
16+ ]
17+ }
18+ } ,
19+ {
20+ id : 2 ,
21+ post_id : 1 ,
22+ someId : 'mw012-7ha19' ,
23+ text : 'How are you?' ,
24+ replies : {
25+ data : [
26+ {
27+ id : 4 ,
28+ comment_id : 2 ,
29+ someId : 'mw023-9ha18' ,
30+ text : 'Hello' ,
31+ } ,
32+ {
33+ id : 5 ,
34+ comment_id : 2 ,
35+ someId : 'mw035-0ha22' ,
36+ text : 'Hello' ,
37+ }
38+ ]
39+ }
40+ }
41+ ]
42+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { Posts as postsEmbedResponse } from './dummy/data/postsEmbed'
99import { Post as postResponse } from './dummy/data/post'
1010import { Post as postEmbedResponse } from './dummy/data/postEmbed'
1111import { Comments as commentsResponse } from './dummy/data/comments'
12+ import { Comments as commentsEmbedResponse } from './dummy/data/commentsEmbed'
1213
1314describe ( 'Model methods' , ( ) => {
1415
@@ -171,6 +172,25 @@ describe('Model methods', () => {
171172
172173 } )
173174
175+ test ( '$get() hits right resource with "data" wrapper (nested object)' , async ( ) => {
176+ axiosMock . onGet ( ) . reply ( ( config ) => {
177+ expect ( config . method ) . toEqual ( 'get' )
178+ expect ( config . url ) . toEqual ( 'http://localhost/posts/1/comments' )
179+
180+ return [ 200 , commentsEmbedResponse ]
181+ } )
182+
183+ const post = new Post ( { id : 1 } )
184+ const comments = await post . comments ( ) . $get ( )
185+
186+ comments . forEach ( comment => {
187+ expect ( comment ) . toBeInstanceOf ( Comment )
188+ comment . replies . data . forEach ( reply => {
189+ expect ( reply ) . toBeInstanceOf ( Comment )
190+ } )
191+ } )
192+ } )
193+
174194 test ( '$get() hits right resource (nested object, custom PK)' , async ( ) => {
175195 Post . prototype [ 'primaryKey' ] = ( ) => {
176196 return 'someId'
You can’t perform that action at this time.
0 commit comments