File tree Expand file tree Collapse file tree 1 file changed +127
-1
lines changed Expand file tree Collapse file tree 1 file changed +127
-1
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,133 @@ describe('VuexORMApollo', () => {
76
76
} ) ;
77
77
78
78
expect ( request . variables ) . toEqual ( { id : 1 } ) ;
79
+ expect ( request . query ) . toEqual ( `
80
+ query User($id: ID!) {
81
+ user(id: $id) {
82
+ id
83
+ name
84
+ posts {
85
+ nodes {
86
+ id
87
+ title
88
+ content
89
+ __typename
90
+ }
91
+ __typename
92
+ }
93
+ __typename
94
+ }
95
+ }
96
+ ` . trim ( ) + "\n" ) ;
79
97
} ) ;
80
- } )
98
+ } ) ;
99
+
100
+ describe ( 'without ID' , ( ) => {
101
+ it ( 'sends the correct query to the API' , async ( ) => {
102
+ const response = {
103
+ data : {
104
+ users : {
105
+ __typename : 'user' ,
106
+ nodes : [
107
+ {
108
+ __typename : 'user' ,
109
+ id : 1 ,
110
+ name : 'Johnny Imba' ,
111
+ posts : {
112
+ __typename : 'post' ,
113
+ nodes : [
114
+ {
115
+ __typename : 'post' ,
116
+ id : 1 ,
117
+ userId : 1 ,
118
+ title : 'Example Post 1' ,
119
+ content : 'Foo'
120
+ } ,
121
+ {
122
+ __typename : 'post' ,
123
+ id : 2 ,
124
+ userId : 1 ,
125
+ title : 'Example Post 2' ,
126
+ content : 'Bar'
127
+ }
128
+ ]
129
+ }
130
+ }
131
+ ]
132
+ }
133
+ }
134
+ } ;
135
+
136
+ const request = await sendWithMockFetch ( response , async ( ) => {
137
+ await store . dispatch ( 'entities/users/fetch' ) ;
138
+ } ) ;
139
+
140
+ expect ( request . variables ) . toEqual ( { } ) ;
141
+ expect ( request . query ) . toEqual ( `
142
+ query Users {
143
+ users {
144
+ nodes {
145
+ id
146
+ name
147
+ posts {
148
+ nodes {
149
+ id
150
+ title
151
+ content
152
+ __typename
153
+ }
154
+ __typename
155
+ }
156
+ __typename
157
+ }
158
+ __typename
159
+ }
160
+ }
161
+ ` . trim ( ) + "\n" ) ;
162
+ } ) ;
163
+ } ) ;
164
+ } ) ;
165
+
166
+
167
+ describe ( 'create' , ( ) => {
168
+ it ( 'sends the correct query to the API' , async ( ) => {
169
+ const response = {
170
+ data : {
171
+ user : {
172
+ __typename : 'user' ,
173
+ id : 1 ,
174
+ name : 'Johnny Imba' ,
175
+ posts : {
176
+ __typename : 'post' ,
177
+ nodes : [ ]
178
+ }
179
+ }
180
+ }
181
+ } ;
182
+
183
+ const request = await sendWithMockFetch ( response , async ( ) => {
184
+ await store . dispatch ( 'entities/users/create' , { user : { name : 'Charlie Brown' } } ) ;
185
+ } ) ;
186
+
187
+ expect ( request . variables ) . toEqual ( { user : { name : 'Charlie Brown' } } ) ;
188
+ expect ( request . query ) . toEqual ( `
189
+ mutation createUser($user: UserInput!) {
190
+ createUser(user: $user) {
191
+ id
192
+ name
193
+ posts {
194
+ nodes {
195
+ id
196
+ title
197
+ content
198
+ __typename
199
+ }
200
+ __typename
201
+ }
202
+ __typename
203
+ }
204
+ }
205
+ ` . trim ( ) + "\n" ) ;
206
+ } ) ;
81
207
} ) ;
82
208
} ) ;
You can’t perform that action at this time.
0 commit comments