@@ -11,8 +11,8 @@ class User extends ORMModel {
11
11
12
12
static fields ( ) {
13
13
return {
14
- id : this . increment ( null ) ,
15
- name : this . string ( null ) ,
14
+ id : this . increment ( 0 ) ,
15
+ name : this . string ( '' ) ,
16
16
posts : this . hasMany ( Post , 'userId' ) ,
17
17
comments : this . hasMany ( Comment , 'userId' )
18
18
} ;
@@ -28,7 +28,7 @@ class Post extends ORMModel {
28
28
id : this . increment ( null ) ,
29
29
content : this . string ( '' ) ,
30
30
title : this . string ( '' ) ,
31
- userId : this . number ( null ) ,
31
+ userId : this . number ( 0 ) ,
32
32
otherId : this . number ( 0 ) , // This is a field which ends with `Id` but doesn't belong to any relation
33
33
user : this . belongsTo ( User , 'userId' ) ,
34
34
comments : this . hasMany ( Comment , 'userId' )
@@ -42,10 +42,10 @@ class Comment extends ORMModel {
42
42
43
43
static fields ( ) {
44
44
return {
45
- id : this . increment ( null ) ,
45
+ id : this . increment ( 0 ) ,
46
46
content : this . string ( '' ) ,
47
- userId : this . number ( null ) ,
48
- postId : this . number ( null ) ,
47
+ userId : this . number ( 0 ) ,
48
+ postId : this . number ( 0 ) ,
49
49
user : this . belongsTo ( User , 'userId' ) ,
50
50
post : this . belongsTo ( Post , 'postId' )
51
51
} ;
@@ -344,30 +344,58 @@ mutation DeleteUser($id: ID!) {
344
344
} ) ;
345
345
346
346
347
- describe ( 'customMutation ' , ( ) => {
347
+ describe ( 'custom mutation ' , ( ) => {
348
348
it ( 'sends the correct query to the API' , async ( ) => {
349
- const user = store . getters [ 'entities/users /find' ] ( 1 ) ;
349
+ const post = store . getters [ 'entities/posts /find' ] ( 1 ) ;
350
350
const response = {
351
351
data : {
352
- signupUser : {
353
- __typename : 'user ' ,
352
+ upvotePost : {
353
+ __typename : 'post ' ,
354
354
id : 1 ,
355
- name : 'Charlie Brown'
355
+ otherId : 13548 ,
356
+ title : 'Example Post 1' ,
357
+ content : 'Foo' ,
358
+ comments : {
359
+ __typename : 'comment' ,
360
+ nodes : [ ]
361
+ } ,
362
+ user : {
363
+ __typename : 'user' ,
364
+ id : 1 ,
365
+ name : 'Johnny Imba' ,
366
+ }
356
367
}
357
368
}
358
369
} ;
359
370
360
371
const request = await sendWithMockFetch ( response , async ( ) => {
361
- await store . dispatch ( 'entities/users /mutate' , { mutation : 'signupUser ' , user , captchaToken : '15' } ) ;
372
+ await store . dispatch ( 'entities/posts /mutate' , { mutation : 'upvotePost ' , post , captchaToken : '15' } ) ;
362
373
} ) ;
363
374
364
375
expect ( request . variables . captchaToken ) . toEqual ( '15' ) ;
365
- expect ( request . variables . user . name ) . toEqual ( user . name ) ;
376
+ expect ( request . variables . post . title ) . toEqual ( post . title ) ;
377
+ expect ( request . variables . post . otherId ) . toEqual ( post . otherId ) ;
378
+ expect ( request . variables . post . userId ) . toEqual ( undefined ) ;
366
379
expect ( request . query ) . toEqual ( `
367
- mutation SignupUser($user: UserInput !, $captchaToken: String!) {
368
- signupUser(user : $user , captchaToken: $captchaToken) {
380
+ mutation UpvotePost($post: PostInput !, $captchaToken: String!) {
381
+ upvotePost(post : $post , captchaToken: $captchaToken) {
369
382
id
370
- name
383
+ content
384
+ title
385
+ otherId
386
+ user {
387
+ id
388
+ name
389
+ __typename
390
+ }
391
+ comments {
392
+ nodes {
393
+ id
394
+ content
395
+ __typename
396
+ }
397
+ __typename
398
+ }
371
399
__typename
372
400
}
373
401
}
0 commit comments