Skip to content

Commit f6d9208

Browse files
authored
Corrected directives test for recent changes
And fixed somethings that I apparently only did locally...
1 parent 9e8519e commit f6d9208

File tree

1 file changed

+74
-59
lines changed

1 file changed

+74
-59
lines changed

graphql-server/tests/directives-tests.js

Lines changed: 74 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ const fetch = require('node-fetch');
1414
async function testDistinct(client) {
1515
// Creates 4 distinct objects of which the third one should fail.
1616
// Then creates 2 new edges of which the first should fail.
17-
17+
1818
// Create Distinct 1
1919
let createDistinct1 = `
2020
mutation {
2121
createDistinctTest(data:{
22-
dummyField: 0
22+
testDummyField: 0
2323
}) {
2424
id
2525
}
@@ -30,13 +30,13 @@ async function testDistinct(client) {
3030
console.error(mutationCreateDistinct1.errors);
3131
return false;
3232
}
33-
let distinct1Id = mutationCreateDistinct1.data[`createDistinct`].id;
34-
33+
let distinct1Id = mutationCreateDistinct1.data[`createDistinctTest`].id;
34+
3535
// Create Distinct 2
3636
let createDistinct2 = `
3737
mutation {
3838
createDistinctTest(data:{
39-
dummyField: 1
39+
testDummyField: 1
4040
}) {
4141
id
4242
}
@@ -47,8 +47,8 @@ async function testDistinct(client) {
4747
console.error(mutationCreateDistinct2.errors);
4848
return false;
4949
}
50-
let distinct2Id = mutationCreateDistinct2.data[`createDistinct`].id;
51-
50+
let distinct2Id = mutationCreateDistinct2.data[`createDistinctTest`].id;
51+
5252
// Create Distinct 3
5353
let createDistinct3 = `
5454
mutation {
@@ -62,14 +62,16 @@ async function testDistinct(client) {
6262
}
6363
}
6464
`;
65-
const mutationCreateDistinct3 = await client.mutate({ mutation: gql`${createDistinct3}` });
66-
if (mutationCreateDistinct3.errors) {
67-
// empty, should actually give errors.
68-
} else {
65+
66+
try {
67+
const mutationCreateDistinct3 = await client.mutate({ mutation: gql`${createDistinct3}` });
6968
console.error("Breaking a @distinct directive did not yield an error!");
7069
return false;
7170
}
72-
71+
catch (e) {
72+
// Should actually throw an error
73+
}
74+
7375
// Create Distinct 4
7476
let createDistinct4 = `
7577
mutation {
@@ -88,8 +90,8 @@ async function testDistinct(client) {
8890
console.error(mutationCreateDistinct4.errors);
8991
return false;
9092
}
91-
let distinct4Id = mutationCreateDistinct4.data[`createDistinct`].id;
92-
93+
let distinct4Id = mutationCreateDistinct4.data[`createDistinctTest`].id;
94+
9395
// Create Distinct Edge 1
9496
let createEdge1 = `
9597
mutation {
@@ -100,15 +102,16 @@ async function testDistinct(client) {
100102
id
101103
}
102104
}
103-
`;
104-
const mutationCreateEdge1 = await client.mutate({ mutation: gql`${createEdge1}` });
105-
if (mutationCreateEdge1.errors) {
106-
// empty, should actually give errors.
107-
} else {
105+
`;
106+
try {
107+
const mutationCreateEdge1 = await client.mutate({ mutation: gql`${createEdge1}` });
108108
console.error("Breaking a @distinct directive did not yield an error!");
109109
return false;
110110
}
111-
111+
catch (e) {
112+
// Should actually throw an error
113+
}
114+
112115
// Create Distinct Edge 2
113116
let createEdge2 = `
114117
mutation {
@@ -125,19 +128,19 @@ async function testDistinct(client) {
125128
console.error(mutationCreateEdge2.errors);
126129
return false;
127130
}
128-
131+
129132
return true;
130133
}
131134

132135
async function testNoloops(client) {
133136
// Create the two connected object.
134137
// Create two edges of which one the first is a loop and should fail
135-
138+
136139
// Create Noloops 1
137140
let createNoloops1 = `
138141
mutation {
139142
createNoloopsTest(data:{
140-
dummyField: 0
143+
testDummyField: 0
141144
}) {
142145
id
143146
}
@@ -148,7 +151,7 @@ async function testNoloops(client) {
148151
console.error(mutationCreateNoloops1.errors);
149152
return false;
150153
}
151-
let noloops1Id = mutationCreateNoloops1.data[`createNoloops`].id;
154+
let noloops1Id = mutationCreateNoloops1.data[`createNoloopsTest`].id;
152155

153156
// Create Noloops 2
154157
let createNoloops2 = `
@@ -165,6 +168,7 @@ async function testNoloops(client) {
165168
console.error(mutationCreateNoloops2.errors);
166169
return false;
167170
}
171+
let noloops2Id = mutationCreateNoloops2.data[`createNoloopsTest`].id;
168172

169173
// Create Loop edge
170174
let createLoop = `
@@ -177,13 +181,15 @@ async function testNoloops(client) {
177181
}
178182
}
179183
`;
180-
const mutationCreateLoop = await client.mutate({ mutation: gql`${createLoop}` });
181-
if (mutationCreateLoop.errors) {
182-
// empty, should actually give errors.
183-
} else {
184+
185+
try {
186+
const mutationCreateLoop = await client.mutate({ mutation: gql`${createLoop}` });
184187
console.error("Breaking a @noloops directive did not yield an error!");
185188
return false;
186189
}
190+
catch (e) {
191+
// Should actually throw an error
192+
}
187193

188194
// Create Not Loop edge
189195
let createNotLoop = `
@@ -197,7 +203,7 @@ async function testNoloops(client) {
197203
}
198204
`;
199205
const mutationCreateNotLoop = await client.mutate({ mutation: gql`${createNotLoop}` });
200-
if (mutationCreateNotLoops.error) {
206+
if (mutationCreateNotLoop.error) {
201207
console.error(mutationCreateNotLoop.errors);
202208
return false;
203209
}
@@ -210,30 +216,32 @@ async function testRequiredForTargetTest(client) {
210216
// Queries the id of the edge, and tries to delete the edge followed by the object.
211217
// Both deletions should fail.
212218
// Lastly delete both objects in valid order
213-
219+
214220
// Create RequiredForTargetTarget 1
215221
let createRequiredForTargetTarget1 = `
216222
mutation {
217223
createRequiredForTargetTarget(data:{
218-
dummyField: 0
224+
testDummyField: 0
219225
}) {
220226
id
221227
}
222228
}
223229
`;
224-
const mutationCreateRequiredForTargetTarget1 = await client.mutate({ mutation: gql`${createRequiredForTargetTarget1}` });
225-
if (mutationCreateRequiredForTargetTarget1.errors) {
226-
// empty, should actually give errors.
227-
} else {
230+
231+
try {
232+
const mutationCreateRequiredForTargetTarget1 = await client.mutate({ mutation: gql`${createRequiredForTargetTarget1}` });
228233
console.error("Breaking a @requiredForTarget directive did not yield an error!");
229234
return false;
230235
}
231-
236+
catch (e) {
237+
// Should actually throw an error
238+
}
239+
232240
// Create
233241
let create = `
234242
mutation {
235243
createRequiredForTargetTest(data:{
236-
target: {create: {dummyField: 1}}
244+
target: {create: {testDummyField: 1}}
237245
}) {
238246
id
239247
}
@@ -245,13 +253,13 @@ async function testRequiredForTargetTest(client) {
245253
return false;
246254
}
247255
let noRequiredSourceId = mutationCreate.data[`createRequiredForTargetTest`].id;
248-
256+
249257
// Get edge id
250258
let getIds = `
251259
query {
252260
requiredForTargetTest(id: "${noRequiredSourceId}") {
253-
target
254-
_outgoingTargetEdges { id }
261+
target { id }
262+
_outgoingTargetEdgesFromRequiredForTargetTest { id }
255263
}
256264
}`;
257265

@@ -260,39 +268,44 @@ async function testRequiredForTargetTest(client) {
260268
if (queryIds.errors) {
261269
console.error(queryIds.errors);
262270
}
263-
let targetId = queryIds.requiredForTargetTest.target.id
264-
let edgeId = queryIds.requiredForTargetTest._outgoingTargetEdges.id;;
265271

272+
let targetId = queryIds.data.requiredForTargetTest.target.id
273+
let edgeId = queryIds.data.requiredForTargetTest._outgoingTargetEdgesFromRequiredForTargetTest.id;
274+
266275
// Delete Edge
267276
let deleteEdge = `
268277
mutation {
269278
deleteTargetEdgeFromRequiredForTargetTest(id: "${edgeId}"){
270279
id
271280
}
272281
}`;
273-
const mutationDeleteEdge = await client.mutate({ mutation: gql`${deleteEdge}` });
274-
if (mutationDeleteEdge.errors) {
275-
// empty, should actually give errors.
276-
} else {
282+
283+
try {
284+
const mutationDeleteEdge = await client.mutate({ mutation: gql`${deleteEdge}` });
277285
console.error("Breaking a @requiredForTarget directive did not yield an error!");
278286
return false;
279287
}
280-
288+
catch (e) {
289+
// Should actually throw an error
290+
}
291+
281292
// Delete Object
282293
let deleteObject = `
283294
mutation {
284295
deleteRequiredForTargetTest(id: "${noRequiredSourceId}"){
285296
id
286297
}
287298
}`;
288-
const mutationDeleteObject = await client.mutate({ mutation: gql`${deleteObject}` });
289-
if (mutationDeleteObject.errors) {
290-
// empty, should actually give errors.
291-
} else {
299+
300+
try {
301+
const mutationDeleteObject = await client.mutate({ mutation: gql`${deleteObject}` });
292302
console.error("Breaking a @requiredForTarget directive did not yield an error!");
293303
return false;
294304
}
295-
305+
catch (e) {
306+
// Should actually throw an error
307+
}
308+
296309
// Delete Target
297310
let deleteTarget = `
298311
mutation {
@@ -305,7 +318,7 @@ async function testRequiredForTargetTest(client) {
305318
console.error(mutationDeleteTarget.errors);
306319
return false;
307320
}
308-
321+
309322
// Delete Target
310323
let deleteSource = `
311324
mutation {
@@ -324,12 +337,12 @@ async function testRequiredForTargetTest(client) {
324337

325338
async function testUniqueForTargetTest(client) {
326339
//
327-
340+
328341
// Create UniqueForTargetTarget
329342
let createUniqueForTargetTarget = `
330343
mutation {
331344
createUniqueForTargetTarget(data:{
332-
dummyField: 0
345+
testDummyField: 0
333346
}) {
334347
id
335348
}
@@ -368,13 +381,15 @@ async function testUniqueForTargetTest(client) {
368381
}
369382
}
370383
`;
371-
const mutationCreateUniqueForTargetTest2 = await client.mutate({ mutation: gql`${createUniqueForTargetTest2}` });
372-
if (mutationCreateUniqueForTargetTest2.errors) {
373-
// empty, should actually give errors.
374-
} else {
384+
385+
try {
386+
const mutationCreateUniqueForTargetTest2 = await client.mutate({ mutation: gql`${createUniqueForTargetTest2}` });
375387
console.error("Breaking a @uniqueForTarget directive did not yield an error!");
376388
return false;
377389
}
390+
catch (e) {
391+
// Should actually throw an error
392+
}
378393

379394
return true;
380395
}

0 commit comments

Comments
 (0)