Skip to content

Commit b033453

Browse files
committed
Add push integration test
1 parent 59bdd46 commit b033453

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/vuex-orm-apollo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export default class VuexORMApollo {
172172

173173
const mutationName = `update${upcaseFirstLetter(model.singularName)}`;
174174
// TODO whats in data? can we determine addModelToArgs from that?
175-
await this.mutate(mutationName, data, dispatch, model, true);
175+
await this.mutate(mutationName, data, dispatch, model, true, false);
176176

177177
// TODO is this really necessary?
178178
return model.baseModel.getters('find')(data.id);

test/integration/VuexORMApollo.spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,50 @@ mutation CreateUser($user: UserInput!) {
205205
`.trim() + "\n");
206206
});
207207
});
208+
209+
210+
describe('push', () => {
211+
it('sends the correct query to the API', async () => {
212+
const response = {
213+
data: {
214+
updateUser: {
215+
__typename: 'user',
216+
id: 1,
217+
name: 'Johnny Imba',
218+
posts: {
219+
__typename: 'post',
220+
nodes: []
221+
}
222+
}
223+
}
224+
};
225+
226+
const request = await sendWithMockFetch(response, async () => {
227+
const user = store.getters['entities/users/find'](1);
228+
user.name = 'Charlie Brown';
229+
230+
await store.dispatch('entities/users/push', { data: user });
231+
});
232+
233+
expect(request.variables).toEqual({ id: 1, user: { name: 'Charlie Brown' } });
234+
expect(request.query).toEqual(`
235+
mutation UpdateUser($user: UserInput!) {
236+
updateUser(user: $user) {
237+
id
238+
name
239+
posts {
240+
nodes {
241+
id
242+
title
243+
content
244+
__typename
245+
}
246+
__typename
247+
}
248+
__typename
249+
}
250+
}
251+
`.trim() + "\n");
252+
});
253+
});
208254
});

0 commit comments

Comments
 (0)