@@ -71,17 +71,18 @@ class Comment extends ORMModel {
71
71
}
72
72
73
73
describe ( 'VuexORMApollo' , ( ) => {
74
- beforeEach ( ( ) => {
74
+ beforeEach ( async ( ) => {
75
75
[ store , vuexOrmApollo ] = createStore ( [ { model : User } , { model : Post } , { model : Video } , { model : Comment } ] ) ;
76
76
77
- store . dispatch ( 'entities/users/insert' , { data : { id : 1 , name : 'Charlie Brown' } } ) ;
78
- store . dispatch ( 'entities/users/insert' , { data : { id : 2 , name : 'Peppermint Patty' } } ) ;
79
- store . dispatch ( 'entities/posts/insert' , { data : { id : 1 , otherId : 9 , userId : 1 , title : 'Example post 1' , content : 'Foo' } } ) ;
80
- store . dispatch ( 'entities/posts/insert' , { data : { id : 2 , otherId : 10 , userId : 1 , title : 'Example post 2' , content : 'Bar' } } ) ;
81
- store . dispatch ( 'entities/videos/insert' , { data : { id : 1 , otherId : 11 , userId : 1 , title : 'Example video' , content : 'Video' } } ) ;
82
- store . dispatch ( 'entities/comments/insert' , { data : { id : 1 , userId : 1 , subjectId : 1 , subjectType : 'videos' , content : 'Example comment 1' } } ) ;
83
- store . dispatch ( 'entities/comments/insert' , { data : { id : 2 , userId : 2 , subjectId : 1 , subjectType : 'posts' , content : 'Example comment 2' } } ) ;
84
- store . dispatch ( 'entities/comments/insert' , { data : { id : 3 , userId : 2 , subjectId : 2 , subjectType : 'posts' , content : 'Example comment 3' } } ) ;
77
+ await User . insert ( { data : { id : 1 , name : 'Charlie Brown' } } ) ;
78
+ await User . insert ( { data : { id : 1 , name : 'Charlie Brown' } } ) ;
79
+ await User . insert ( { data : { id : 2 , name : 'Peppermint Patty' } } ) ;
80
+ await Post . insert ( { data : { id : 1 , otherId : 9 , userId : 1 , title : 'Example post 1' , content : 'Foo' } } ) ;
81
+ await Post . insert ( { data : { id : 2 , otherId : 10 , userId : 1 , title : 'Example post 2' , content : 'Bar' } } ) ;
82
+ await Video . insert ( { data : { id : 1 , otherId : 11 , userId : 1 , title : 'Example video' , content : 'Video' } } ) ;
83
+ await Comment . insert ( { data : { id : 1 , userId : 1 , subjectId : 1 , subjectType : 'videos' , content : 'Example comment 1' } } ) ;
84
+ await Comment . insert ( { data : { id : 2 , userId : 2 , subjectId : 1 , subjectType : 'posts' , content : 'Example comment 2' } } ) ;
85
+ await Comment . insert ( { data : { id : 3 , userId : 2 , subjectId : 2 , subjectType : 'posts' , content : 'Example comment 3' } } ) ;
85
86
} ) ;
86
87
87
88
describe ( 'fetch' , ( ) => {
@@ -114,7 +115,7 @@ describe('VuexORMApollo', () => {
114
115
} ;
115
116
116
117
let request = await sendWithMockFetch ( response , async ( ) => {
117
- await store . dispatch ( 'entities/posts/ fetch' , { filter : { id : 42 } } ) ;
118
+ await Post . fetch ( 42 ) ;
118
119
} ) ;
119
120
expect ( request ) . not . toEqual ( null ) ;
120
121
@@ -165,17 +166,17 @@ query Post($id: ID!) {
165
166
} ;
166
167
167
168
let request = await sendWithMockFetch ( response , async ( ) => {
168
- await store . dispatch ( 'entities/users/ fetch' , { filter : { id : 1 } } ) ;
169
+ await User . fetch ( 1 ) ;
169
170
} ) ;
170
171
expect ( request ) . not . toEqual ( null ) ;
171
172
172
173
request = await sendWithMockFetch ( response , async ( ) => {
173
- await store . dispatch ( 'entities/users/ fetch' , { filter : { id : 1 } } ) ;
174
+ await User . fetch ( 1 ) ;
174
175
} , true ) ;
175
176
expect ( request ) . toEqual ( null ) ;
176
177
177
178
request = await sendWithMockFetch ( response , async ( ) => {
178
- await store . dispatch ( 'entities/users/ fetch' , { filter : { id : 1 } , bypassCache : true } ) ;
179
+ await User . fetch ( 1 , true ) ;
179
180
} ) ;
180
181
expect ( request ) . not . toEqual ( null ) ;
181
182
} ) ;
@@ -192,7 +193,7 @@ query Post($id: ID!) {
192
193
} ;
193
194
194
195
const request = await sendWithMockFetch ( response , async ( ) => {
195
- await store . dispatch ( 'entities/users/ fetch' , { filter : { id : 1 } } ) ;
196
+ await User . fetch ( 1 ) ;
196
197
} ) ;
197
198
198
199
expect ( request . variables ) . toEqual ( { id : 1 } ) ;
@@ -226,7 +227,7 @@ query User($id: ID!) {
226
227
} ;
227
228
228
229
const request = await sendWithMockFetch ( response , async ( ) => {
229
- await store . dispatch ( 'entities/users/ fetch' , { filter : { active : true } } ) ;
230
+ await User . fetch ( { active : true } ) ;
230
231
} ) ;
231
232
232
233
expect ( request . variables ) . toEqual ( { active : true } ) ;
@@ -263,7 +264,7 @@ query Users($active: Boolean!) {
263
264
} ;
264
265
265
266
const request = await sendWithMockFetch ( response , async ( ) => {
266
- await store . dispatch ( 'entities/users/ fetch' ) ;
267
+ await User . fetch ( ) ;
267
268
} ) ;
268
269
269
270
expect ( request . variables ) . toEqual ( { } ) ;
@@ -314,7 +315,8 @@ query Users {
314
315
} ;
315
316
316
317
const request = await sendWithMockFetch ( response , async ( ) => {
317
- await store . dispatch ( 'entities/posts/persist' , { id : 1 } ) ;
318
+ const post = Post . find ( 1 ) ;
319
+ await post . $persist ( ) ;
318
320
} ) ;
319
321
320
322
expect ( request . variables ) . toEqual ( {
@@ -378,7 +380,7 @@ mutation CreatePost($post: PostInput!) {
378
380
const user = User . find ( 1 ) ;
379
381
user . name = 'Snoopy' ;
380
382
381
- await store . dispatch ( 'entities/users/ push' , { data : user } ) ;
383
+ await user . $ push( ) ;
382
384
} ) ;
383
385
384
386
expect ( request . variables ) . toEqual ( { id : 1 , user : { id : 1 , name : 'Snoopy' } } ) ;
@@ -408,7 +410,8 @@ mutation UpdateUser($id: ID!, $user: UserInput!) {
408
410
} ;
409
411
410
412
const request = await sendWithMockFetch ( response , async ( ) => {
411
- await store . dispatch ( 'entities/users/destroy' , { id : 1 } ) ;
413
+ const user = User . find ( 1 ) ;
414
+ await user . $destroy ( ) ;
412
415
} ) ;
413
416
414
417
expect ( request . variables ) . toEqual ( { id : 1 } ) ;
@@ -450,16 +453,14 @@ mutation DeleteUser($id: ID!) {
450
453
} ;
451
454
452
455
const request = await sendWithMockFetch ( response , async ( ) => {
453
- await store . dispatch ( 'entities/posts/ mutate' , { mutation : 'upvotePost' , post , captchaToken : '15' } ) ;
456
+ await post . $ mutate( { mutation : 'upvotePost' , captchaToken : '15' } ) ;
454
457
} ) ;
455
458
456
459
expect ( request . variables . captchaToken ) . toEqual ( '15' ) ;
457
- expect ( request . variables . post . title ) . toEqual ( post . title ) ;
458
- expect ( request . variables . post . otherId ) . toEqual ( post . otherId ) ;
459
- expect ( request . variables . post . userId ) . toEqual ( 1 ) ;
460
+ expect ( request . variables . id ) . toEqual ( post . id ) ;
460
461
expect ( request . query ) . toEqual ( `
461
- mutation UpvotePost($post: PostInput !, $captchaToken: String !) {
462
- upvotePost(post : $post, captchaToken : $captchaToken ) {
462
+ mutation UpvotePost($captchaToken: String !, $id: ID !) {
463
+ upvotePost(captchaToken : $captchaToken, id : $id ) {
463
464
id
464
465
content
465
466
title
@@ -488,7 +489,7 @@ mutation UpvotePost($post: PostInput!, $captchaToken: String!) {
488
489
489
490
describe ( '$isPersisted' , ( ) => {
490
491
it ( 'is false for newly created records' , async ( ) => {
491
- const insertedData = await store . dispatch ( 'entities/users/ insert' , { data : { name : 'Snoopy' } } ) ;
492
+ const insertedData = await User . insert ( { data : { name : 'Snoopy' } } ) ;
492
493
let user = insertedData . users [ 0 ] ;
493
494
expect ( user . $isPersisted ) . toBeFalsy ( ) ;
494
495
@@ -497,7 +498,7 @@ mutation UpvotePost($post: PostInput!, $captchaToken: String!) {
497
498
} ) ;
498
499
499
500
it ( 'is true for persisted records' , async ( ) => {
500
- const insertedData = await store . dispatch ( 'entities/users/ insert' , { data : { name : 'Snoopy' } } ) ;
501
+ const insertedData = await User . insert ( { data : { name : 'Snoopy' } } ) ;
501
502
let user = insertedData . users [ 0 ] ;
502
503
const response = {
503
504
data : {
@@ -516,7 +517,7 @@ mutation UpvotePost($post: PostInput!, $captchaToken: String!) {
516
517
expect ( user . $isPersisted ) . toBeFalsy ( ) ;
517
518
518
519
await sendWithMockFetch ( response , async ( ) => {
519
- user = await store . dispatch ( 'entities/users/ persist' , { id : 1 } ) ;
520
+ user = await user . $ persist( ) ;
520
521
} ) ;
521
522
522
523
expect ( user . $isPersisted ) . toBeTruthy ( ) ;
@@ -553,7 +554,7 @@ mutation UpvotePost($post: PostInput!, $captchaToken: String!) {
553
554
} ;
554
555
555
556
await sendWithMockFetch ( response , async ( ) => {
556
- await store . dispatch ( 'entities/users/ fetch' , { filter : { id : 1 } } ) ;
557
+ await User . fetch ( 1 ) ;
557
558
} ) ;
558
559
559
560
const user = User . find ( 1 ) ;
0 commit comments