@@ -3,13 +3,14 @@ import User from './dummy/models/User'
33import Comment from './dummy/models/Comment'
44import { Model } from '../src'
55import axios from 'axios'
6- import MockAdapter from 'axios-mock-adapter' ;
6+ import MockAdapter from 'axios-mock-adapter'
77import { Posts as postsResponse } from './dummy/data/posts'
88import { 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'
1212import { Comments as commentsEmbedResponse } from './dummy/data/commentsEmbed'
13+ import Tag from './dummy/models/Tag'
1314
1415describe ( 'Model methods' , ( ) => {
1516
@@ -50,6 +51,9 @@ describe('Model methods', () => {
5051 expect ( post ) . toEqual ( postsResponse [ 0 ] )
5152 expect ( post ) . toBeInstanceOf ( Post )
5253 expect ( post . user ) . toBeInstanceOf ( User )
54+ post . relationships . tags . forEach ( tag => {
55+ expect ( tag ) . toBeInstanceOf ( Tag )
56+ } )
5357 } )
5458
5559 test ( '$first() returns first object in array as instance of such Model' , async ( ) => {
@@ -61,6 +65,9 @@ describe('Model methods', () => {
6165 expect ( post ) . toEqual ( postsEmbedResponse . data [ 0 ] )
6266 expect ( post ) . toBeInstanceOf ( Post )
6367 expect ( post . user ) . toBeInstanceOf ( User )
68+ post . relationships . tags . forEach ( tag => {
69+ expect ( tag ) . toBeInstanceOf ( Tag )
70+ } )
6471 } )
6572
6673 test ( 'first() method returns a empty object when no items have found' , async ( ) => {
@@ -77,6 +84,9 @@ describe('Model methods', () => {
7784 expect ( post ) . toEqual ( postResponse )
7885 expect ( post ) . toBeInstanceOf ( Post )
7986 expect ( post . user ) . toBeInstanceOf ( User )
87+ post . relationships . tags . forEach ( tag => {
88+ expect ( tag ) . toBeInstanceOf ( Tag )
89+ } )
8090 } )
8191
8292 test ( '$find() handles request with "data" wrapper' , async ( ) => {
@@ -87,6 +97,9 @@ describe('Model methods', () => {
8797 expect ( post ) . toEqual ( postEmbedResponse . data )
8898 expect ( post ) . toBeInstanceOf ( Post )
8999 expect ( post . user ) . toBeInstanceOf ( User )
100+ post . relationships . tags . data . forEach ( tag => {
101+ expect ( tag ) . toBeInstanceOf ( Tag )
102+ } )
90103 } )
91104
92105 test ( '$find() handles request without "data" wrapper' , async ( ) => {
@@ -97,7 +110,9 @@ describe('Model methods', () => {
97110 expect ( post ) . toEqual ( postResponse )
98111 expect ( post ) . toBeInstanceOf ( Post )
99112 expect ( post . user ) . toBeInstanceOf ( User )
100-
113+ post . relationships . tags . forEach ( tag => {
114+ expect ( tag ) . toBeInstanceOf ( Tag )
115+ } )
101116 } )
102117
103118 test ( 'get() method returns a array of objects as instance of suchModel' , async ( ) => {
@@ -108,7 +123,10 @@ describe('Model methods', () => {
108123 posts . forEach ( post => {
109124 expect ( post ) . toBeInstanceOf ( Post )
110125 expect ( post . user ) . toBeInstanceOf ( User )
111- } ) ;
126+ post . relationships . tags . forEach ( tag => {
127+ expect ( tag ) . toBeInstanceOf ( Tag )
128+ } )
129+ } )
112130 } )
113131
114132 test ( 'get() hits right resource (nested object)' , async ( ) => {
@@ -225,6 +243,16 @@ describe('Model methods', () => {
225243 firstname : 'John' ,
226244 lastname : 'Doe' ,
227245 age : 25
246+ } ,
247+ relationships : {
248+ tags : [
249+ {
250+ name : 'super'
251+ } ,
252+ {
253+ name : 'awesome'
254+ }
255+ ]
228256 }
229257 }
230258
@@ -242,6 +270,9 @@ describe('Model methods', () => {
242270 expect ( post ) . toEqual ( _postResponse )
243271 expect ( post ) . toBeInstanceOf ( Post )
244272 expect ( post . user ) . toBeInstanceOf ( User )
273+ post . relationships . tags . forEach ( tag => {
274+ expect ( tag ) . toBeInstanceOf ( Tag )
275+ } )
245276 } )
246277
247278 test ( 'save() method makes a PUT request when ID of object exists' , async ( ) => {
@@ -490,7 +521,7 @@ describe('Model methods', () => {
490521
491522 posts . forEach ( post => {
492523 expect ( post ) . toBeInstanceOf ( Post )
493- } ) ;
524+ } )
494525 } )
495526
496527 test ( 'attach() method hits right endpoint with a POST request' , async ( ) => {
0 commit comments