@@ -3,13 +3,14 @@ import User from './dummy/models/User'
3
3
import Comment from './dummy/models/Comment'
4
4
import { Model } from '../src'
5
5
import axios from 'axios'
6
- import MockAdapter from 'axios-mock-adapter' ;
6
+ import MockAdapter from 'axios-mock-adapter'
7
7
import { Posts as postsResponse } from './dummy/data/posts'
8
8
import { Posts as postsEmbedResponse } from './dummy/data/postsEmbed'
9
9
import { Post as postResponse } from './dummy/data/post'
10
10
import { Post as postEmbedResponse } from './dummy/data/postEmbed'
11
11
import { Comments as commentsResponse } from './dummy/data/comments'
12
12
import { Comments as commentsEmbedResponse } from './dummy/data/commentsEmbed'
13
+ import Tag from './dummy/models/Tag'
13
14
14
15
describe ( 'Model methods' , ( ) => {
15
16
@@ -50,6 +51,9 @@ describe('Model methods', () => {
50
51
expect ( post ) . toEqual ( postsResponse [ 0 ] )
51
52
expect ( post ) . toBeInstanceOf ( Post )
52
53
expect ( post . user ) . toBeInstanceOf ( User )
54
+ post . relationships . tags . forEach ( tag => {
55
+ expect ( tag ) . toBeInstanceOf ( Tag )
56
+ } )
53
57
} )
54
58
55
59
test ( '$first() returns first object in array as instance of such Model' , async ( ) => {
@@ -61,6 +65,9 @@ describe('Model methods', () => {
61
65
expect ( post ) . toEqual ( postsEmbedResponse . data [ 0 ] )
62
66
expect ( post ) . toBeInstanceOf ( Post )
63
67
expect ( post . user ) . toBeInstanceOf ( User )
68
+ post . relationships . tags . forEach ( tag => {
69
+ expect ( tag ) . toBeInstanceOf ( Tag )
70
+ } )
64
71
} )
65
72
66
73
test ( 'first() method returns a empty object when no items have found' , async ( ) => {
@@ -77,6 +84,9 @@ describe('Model methods', () => {
77
84
expect ( post ) . toEqual ( postResponse )
78
85
expect ( post ) . toBeInstanceOf ( Post )
79
86
expect ( post . user ) . toBeInstanceOf ( User )
87
+ post . relationships . tags . forEach ( tag => {
88
+ expect ( tag ) . toBeInstanceOf ( Tag )
89
+ } )
80
90
} )
81
91
82
92
test ( '$find() handles request with "data" wrapper' , async ( ) => {
@@ -87,6 +97,9 @@ describe('Model methods', () => {
87
97
expect ( post ) . toEqual ( postEmbedResponse . data )
88
98
expect ( post ) . toBeInstanceOf ( Post )
89
99
expect ( post . user ) . toBeInstanceOf ( User )
100
+ post . relationships . tags . data . forEach ( tag => {
101
+ expect ( tag ) . toBeInstanceOf ( Tag )
102
+ } )
90
103
} )
91
104
92
105
test ( '$find() handles request without "data" wrapper' , async ( ) => {
@@ -97,7 +110,9 @@ describe('Model methods', () => {
97
110
expect ( post ) . toEqual ( postResponse )
98
111
expect ( post ) . toBeInstanceOf ( Post )
99
112
expect ( post . user ) . toBeInstanceOf ( User )
100
-
113
+ post . relationships . tags . forEach ( tag => {
114
+ expect ( tag ) . toBeInstanceOf ( Tag )
115
+ } )
101
116
} )
102
117
103
118
test ( 'get() method returns a array of objects as instance of suchModel' , async ( ) => {
@@ -108,7 +123,10 @@ describe('Model methods', () => {
108
123
posts . forEach ( post => {
109
124
expect ( post ) . toBeInstanceOf ( Post )
110
125
expect ( post . user ) . toBeInstanceOf ( User )
111
- } ) ;
126
+ post . relationships . tags . forEach ( tag => {
127
+ expect ( tag ) . toBeInstanceOf ( Tag )
128
+ } )
129
+ } )
112
130
} )
113
131
114
132
test ( 'get() hits right resource (nested object)' , async ( ) => {
@@ -225,6 +243,16 @@ describe('Model methods', () => {
225
243
firstname : 'John' ,
226
244
lastname : 'Doe' ,
227
245
age : 25
246
+ } ,
247
+ relationships : {
248
+ tags : [
249
+ {
250
+ name : 'super'
251
+ } ,
252
+ {
253
+ name : 'awesome'
254
+ }
255
+ ]
228
256
}
229
257
}
230
258
@@ -242,6 +270,9 @@ describe('Model methods', () => {
242
270
expect ( post ) . toEqual ( _postResponse )
243
271
expect ( post ) . toBeInstanceOf ( Post )
244
272
expect ( post . user ) . toBeInstanceOf ( User )
273
+ post . relationships . tags . forEach ( tag => {
274
+ expect ( tag ) . toBeInstanceOf ( Tag )
275
+ } )
245
276
} )
246
277
247
278
test ( 'save() method makes a PUT request when ID of object exists' , async ( ) => {
@@ -490,7 +521,7 @@ describe('Model methods', () => {
490
521
491
522
posts . forEach ( post => {
492
523
expect ( post ) . toBeInstanceOf ( Post )
493
- } ) ;
524
+ } )
494
525
} )
495
526
496
527
test ( 'attach() method hits right endpoint with a POST request' , async ( ) => {
0 commit comments