@@ -71,17 +71,18 @@ class Comment extends ORMModel {
7171}
7272
7373describe ( 'VuexORMApollo' , ( ) => {
74- beforeEach ( ( ) => {
74+ beforeEach ( async ( ) => {
7575 [ store , vuexOrmApollo ] = createStore ( [ { model : User } , { model : Post } , { model : Video } , { model : Comment } ] ) ;
7676
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' } } ) ;
8586 } ) ;
8687
8788 describe ( 'fetch' , ( ) => {
@@ -114,7 +115,7 @@ describe('VuexORMApollo', () => {
114115 } ;
115116
116117 let request = await sendWithMockFetch ( response , async ( ) => {
117- await store . dispatch ( 'entities/posts/ fetch' , { filter : { id : 42 } } ) ;
118+ await Post . fetch ( 42 ) ;
118119 } ) ;
119120 expect ( request ) . not . toEqual ( null ) ;
120121
@@ -165,17 +166,17 @@ query Post($id: ID!) {
165166 } ;
166167
167168 let request = await sendWithMockFetch ( response , async ( ) => {
168- await store . dispatch ( 'entities/users/ fetch' , { filter : { id : 1 } } ) ;
169+ await User . fetch ( 1 ) ;
169170 } ) ;
170171 expect ( request ) . not . toEqual ( null ) ;
171172
172173 request = await sendWithMockFetch ( response , async ( ) => {
173- await store . dispatch ( 'entities/users/ fetch' , { filter : { id : 1 } } ) ;
174+ await User . fetch ( 1 ) ;
174175 } , true ) ;
175176 expect ( request ) . toEqual ( null ) ;
176177
177178 request = await sendWithMockFetch ( response , async ( ) => {
178- await store . dispatch ( 'entities/users/ fetch' , { filter : { id : 1 } , bypassCache : true } ) ;
179+ await User . fetch ( 1 , true ) ;
179180 } ) ;
180181 expect ( request ) . not . toEqual ( null ) ;
181182 } ) ;
@@ -192,7 +193,7 @@ query Post($id: ID!) {
192193 } ;
193194
194195 const request = await sendWithMockFetch ( response , async ( ) => {
195- await store . dispatch ( 'entities/users/ fetch' , { filter : { id : 1 } } ) ;
196+ await User . fetch ( 1 ) ;
196197 } ) ;
197198
198199 expect ( request . variables ) . toEqual ( { id : 1 } ) ;
@@ -226,7 +227,7 @@ query User($id: ID!) {
226227 } ;
227228
228229 const request = await sendWithMockFetch ( response , async ( ) => {
229- await store . dispatch ( 'entities/users/ fetch' , { filter : { active : true } } ) ;
230+ await User . fetch ( { active : true } ) ;
230231 } ) ;
231232
232233 expect ( request . variables ) . toEqual ( { active : true } ) ;
@@ -263,7 +264,7 @@ query Users($active: Boolean!) {
263264 } ;
264265
265266 const request = await sendWithMockFetch ( response , async ( ) => {
266- await store . dispatch ( 'entities/users/ fetch' ) ;
267+ await User . fetch ( ) ;
267268 } ) ;
268269
269270 expect ( request . variables ) . toEqual ( { } ) ;
@@ -314,7 +315,8 @@ query Users {
314315 } ;
315316
316317 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 ( ) ;
318320 } ) ;
319321
320322 expect ( request . variables ) . toEqual ( {
@@ -378,7 +380,7 @@ mutation CreatePost($post: PostInput!) {
378380 const user = User . find ( 1 ) ;
379381 user . name = 'Snoopy' ;
380382
381- await store . dispatch ( 'entities/users/ push' , { data : user } ) ;
383+ await user . $ push( ) ;
382384 } ) ;
383385
384386 expect ( request . variables ) . toEqual ( { id : 1 , user : { id : 1 , name : 'Snoopy' } } ) ;
@@ -408,7 +410,8 @@ mutation UpdateUser($id: ID!, $user: UserInput!) {
408410 } ;
409411
410412 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 ( ) ;
412415 } ) ;
413416
414417 expect ( request . variables ) . toEqual ( { id : 1 } ) ;
@@ -450,16 +453,14 @@ mutation DeleteUser($id: ID!) {
450453 } ;
451454
452455 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' } ) ;
454457 } ) ;
455458
456459 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 ) ;
460461 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 ) {
463464 id
464465 content
465466 title
@@ -488,7 +489,7 @@ mutation UpvotePost($post: PostInput!, $captchaToken: String!) {
488489
489490 describe ( '$isPersisted' , ( ) => {
490491 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' } } ) ;
492493 let user = insertedData . users [ 0 ] ;
493494 expect ( user . $isPersisted ) . toBeFalsy ( ) ;
494495
@@ -497,7 +498,7 @@ mutation UpvotePost($post: PostInput!, $captchaToken: String!) {
497498 } ) ;
498499
499500 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' } } ) ;
501502 let user = insertedData . users [ 0 ] ;
502503 const response = {
503504 data : {
@@ -516,7 +517,7 @@ mutation UpvotePost($post: PostInput!, $captchaToken: String!) {
516517 expect ( user . $isPersisted ) . toBeFalsy ( ) ;
517518
518519 await sendWithMockFetch ( response , async ( ) => {
519- user = await store . dispatch ( 'entities/users/ persist' , { id : 1 } ) ;
520+ user = await user . $ persist( ) ;
520521 } ) ;
521522
522523 expect ( user . $isPersisted ) . toBeTruthy ( ) ;
@@ -553,7 +554,7 @@ mutation UpvotePost($post: PostInput!, $captchaToken: String!) {
553554 } ;
554555
555556 await sendWithMockFetch ( response , async ( ) => {
556- await store . dispatch ( 'entities/users/ fetch' , { filter : { id : 1 } } ) ;
557+ await User . fetch ( 1 ) ;
557558 } ) ;
558559
559560 const user = User . find ( 1 ) ;
0 commit comments