Skip to content

Commit 4b04b05

Browse files
committed
Better custom mutation spec
1 parent 530f0d7 commit 4b04b05

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

test/integration/VuexORMApollo.spec.js

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class User extends ORMModel {
1111

1212
static fields () {
1313
return {
14-
id: this.increment(null),
15-
name: this.string(null),
14+
id: this.increment(0),
15+
name: this.string(''),
1616
posts: this.hasMany(Post, 'userId'),
1717
comments: this.hasMany(Comment, 'userId')
1818
};
@@ -28,7 +28,7 @@ class Post extends ORMModel {
2828
id: this.increment(null),
2929
content: this.string(''),
3030
title: this.string(''),
31-
userId: this.number(null),
31+
userId: this.number(0),
3232
otherId: this.number(0), // This is a field which ends with `Id` but doesn't belong to any relation
3333
user: this.belongsTo(User, 'userId'),
3434
comments: this.hasMany(Comment, 'userId')
@@ -42,10 +42,10 @@ class Comment extends ORMModel {
4242

4343
static fields () {
4444
return {
45-
id: this.increment(null),
45+
id: this.increment(0),
4646
content: this.string(''),
47-
userId: this.number(null),
48-
postId: this.number(null),
47+
userId: this.number(0),
48+
postId: this.number(0),
4949
user: this.belongsTo(User, 'userId'),
5050
post: this.belongsTo(Post, 'postId')
5151
};
@@ -344,30 +344,58 @@ mutation DeleteUser($id: ID!) {
344344
});
345345

346346

347-
describe('customMutation', () => {
347+
describe('custom mutation', () => {
348348
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);
350350
const response = {
351351
data: {
352-
signupUser: {
353-
__typename: 'user',
352+
upvotePost: {
353+
__typename: 'post',
354354
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+
}
356367
}
357368
}
358369
};
359370

360371
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' });
362373
});
363374

364375
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);
366379
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) {
369382
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+
}
371399
__typename
372400
}
373401
}

0 commit comments

Comments
 (0)