/
client-spec.js
102 lines (96 loc) · 2.07 KB
/
client-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// @ts-check
import { gql } from '@apollo/client'
import { client } from '../../src/graphql-client'
import { todos } from '../../db'
import { createItems } from './utils'
import { deleteAll } from './utils-using-client'
// make individual GraphQL calls using the app's own client
describe('GraphQL client', { tags: '@client' }, () => {
before(() => {
deleteAll()
// @ts-ignore
createItems(todos)
})
it('gets all todos (id, title)', () => {
const query = gql`
query listTodos {
# operation name
allTodos {
# fields to pick
id
title
completed
}
}
`
cy.wrap(
client.query({
query,
}),
)
.its('data.allTodos')
.should('have.length.gte', 2)
.its('0')
.should('deep.include', {
title: todos[0].title,
completed: todos[0].completed,
__typename: 'Todo',
})
.and('have.property', 'id')
})
it('gets second todo', () => {
const query = gql`
query getTodo {
# operation name
Todo(id: 1) {
# fields to pick
id
title
completed
}
}
`
cy.wrap(
client.query({
query,
}),
)
.its('data.Todo')
.should('deep.include', {
...todos[1],
// ID will be dynamically generated
// after deleting all existing todos
id: '1',
__typename: 'Todo',
})
})
it('mutates the first todo as completed', () => {
const m = gql`
mutation updateTodo($id: ID!, $completed: Boolean!) {
# operation name
updateTodo(id: $id, completed: $completed) {
# return fields
id
title
completed
}
}
`
cy.wrap(
client.mutate({
mutation: m,
variables: {
id: '0',
completed: true,
},
}),
)
.its('data.updateTodo')
.should('deep.equal', {
...todos[0],
id: '0',
completed: true,
__typename: 'Todo',
})
})
})