Skip to content

Commit 16a39a8

Browse files
committed
Updated tests
1 parent 8105092 commit 16a39a8

16 files changed

+385
-27
lines changed

src/HotChocolate/Core/test/Types.Tests/Types/OneOfIntegrationTests.cs

Lines changed: 207 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ public async Task A_is_null_and_B_is_set_Error()
3434
.MatchSnapshotAsync();
3535
}
3636

37+
[Fact]
38+
public async Task A_is_null_and_B_is_null_Error()
39+
{
40+
// Error: Exactly one key must be specified
41+
await new ServiceCollection()
42+
.AddGraphQL()
43+
.AddQueryType<Query>()
44+
.ModifyOptions(o => o.EnableOneOf = true)
45+
.ExecuteRequestAsync("{ example(input: { a: null, b: null }) }")
46+
.MatchSnapshotAsync();
47+
}
48+
3749
[Fact]
3850
public async Task A_is_null_Error()
3951
{
@@ -57,6 +69,18 @@ public async Task B_is_set_Valid()
5769
.MatchSnapshotAsync();
5870
}
5971

72+
[Fact]
73+
public async Task Input_is_empty_object_Error()
74+
{
75+
// Error: Exactly one key must be specified
76+
await new ServiceCollection()
77+
.AddGraphQL()
78+
.AddQueryType<Query>()
79+
.ModifyOptions(o => o.EnableOneOf = true)
80+
.ExecuteRequestAsync("{ example(input: { }) }")
81+
.MatchSnapshotAsync();
82+
}
83+
6084
[Fact]
6185
public async Task A_is_variable_and_B_is_set_Error()
6286
{
@@ -67,8 +91,40 @@ public async Task A_is_variable_and_B_is_set_Error()
6791
.ModifyOptions(o => o.EnableOneOf = true)
6892
.ExecuteRequestAsync(
6993
OperationRequestBuilder.New()
70-
.SetDocument("query($var: String!) { example(input: { a: $var, b: 123 }) }")
71-
.SetVariableValues(new Dictionary<string, object?> { { "var", null } })
94+
.SetDocument("query($a: String!) { example(input: { a: $a, b: 123 }) }")
95+
.SetVariableValues(new Dictionary<string, object?> { { "a", null } })
96+
.Build())
97+
.MatchSnapshotAsync();
98+
}
99+
100+
[Fact]
101+
public async Task A_is_unset_variable_and_B_is_set_Error()
102+
{
103+
// Error: Exactly one key must be specified
104+
await new ServiceCollection()
105+
.AddGraphQL()
106+
.AddQueryType<Query>()
107+
.ModifyOptions(o => o.EnableOneOf = true)
108+
.ExecuteRequestAsync(
109+
OperationRequestBuilder.New()
110+
.SetDocument("query($a: String!) { example(input: { a: $a, b: 123 }) }")
111+
.Build())
112+
.MatchSnapshotAsync();
113+
}
114+
115+
[Fact]
116+
public async Task A_is_variable_and_B_is_unset_variable_Error()
117+
{
118+
// Error: Exactly one key must be specified
119+
await new ServiceCollection()
120+
.AddGraphQL()
121+
.AddQueryType<Query>()
122+
.ModifyOptions(o => o.EnableOneOf = true)
123+
.ExecuteRequestAsync(
124+
OperationRequestBuilder.New()
125+
.SetDocument(
126+
"query($a: String!, $b: Int!) { example(input: { a: $a, b: $b }) }")
127+
.SetVariableValues(new Dictionary<string, object?> { { "a", "abc" } })
72128
.Build())
73129
.MatchSnapshotAsync();
74130
}
@@ -82,14 +138,14 @@ public async Task B_is_variable_and_var_is_123_Valid()
82138
.ModifyOptions(o => o.EnableOneOf = true)
83139
.ExecuteRequestAsync(
84140
OperationRequestBuilder.New()
85-
.SetDocument("query($var: Int!) { example(input: { b: $var }) }")
86-
.SetVariableValues(new Dictionary<string, object?> { { "var", 123 } })
141+
.SetDocument("query($b: Int!) { example(input: { b: $b }) }")
142+
.SetVariableValues(new Dictionary<string, object?> { { "b", 123 } })
87143
.Build())
88144
.MatchSnapshotAsync();
89145
}
90146

91147
[Fact]
92-
public async Task Var_is_object_with_field_b_set_to_123_Valid()
148+
public async Task Var_is_object_with_field_B_set_to_123_Valid()
93149
{
94150
await new ServiceCollection()
95151
.AddGraphQL()
@@ -105,11 +161,100 @@ public async Task Var_is_object_with_field_b_set_to_123_Valid()
105161
.MatchSnapshotAsync();
106162
}
107163

164+
[Fact]
165+
public async Task Var_is_object_with_A_set_to_abc_and_B_set_to_123_Error()
166+
{
167+
// Error: Exactly one key must be specified
168+
await new ServiceCollection()
169+
.AddGraphQL()
170+
.AddQueryType<Query>()
171+
.ModifyOptions(o => o.EnableOneOf = true)
172+
.ExecuteRequestAsync(
173+
OperationRequestBuilder.New()
174+
.SetDocument("query($var: ExampleInput!) { example(input: $var) }")
175+
.SetVariableValues(
176+
new Dictionary<string, object?>
177+
{
178+
{
179+
"var",
180+
new ObjectValueNode(
181+
new ObjectFieldNode("a", "abc"),
182+
new ObjectFieldNode("b", 123))
183+
}
184+
})
185+
.Build())
186+
.MatchSnapshotAsync();
187+
}
188+
189+
[Fact]
190+
public async Task Var_is_object_with_A_set_to_abc_and_B_set_to_null_Error()
191+
{
192+
// Error: Exactly one key must be specified
193+
await new ServiceCollection()
194+
.AddGraphQL()
195+
.AddQueryType<Query>()
196+
.ModifyOptions(o => o.EnableOneOf = true)
197+
.ExecuteRequestAsync(
198+
OperationRequestBuilder.New()
199+
.SetDocument("query($var: ExampleInput!) { example(input: $var) }")
200+
.SetVariableValues(
201+
new Dictionary<string, object?>
202+
{
203+
{
204+
"var",
205+
new ObjectValueNode(
206+
new ObjectFieldNode("a", "abc"),
207+
new ObjectFieldNode("b", NullValueNode.Default))
208+
}
209+
})
210+
.Build())
211+
.MatchSnapshotAsync();
212+
}
213+
214+
[Fact]
215+
public async Task Var_is_object_with_A_set_to_null_Error()
216+
{
217+
// Error: Value for member field {a} must be non-null
218+
await new ServiceCollection()
219+
.AddGraphQL()
220+
.AddQueryType<Query>()
221+
.ModifyOptions(o => o.EnableOneOf = true)
222+
.ExecuteRequestAsync(
223+
OperationRequestBuilder.New()
224+
.SetDocument("query($var: ExampleInput!) { example(input: $var) }")
225+
.SetVariableValues(
226+
new Dictionary<string, object?>
227+
{
228+
{
229+
"var",
230+
new ObjectValueNode(new ObjectFieldNode("a", NullValueNode.Default))
231+
}
232+
})
233+
.Build())
234+
.MatchSnapshotAsync();
235+
}
236+
237+
[Fact]
238+
public async Task Var_is_empty_object_Error()
239+
{
240+
// Error: Exactly one key must be specified
241+
await new ServiceCollection()
242+
.AddGraphQL()
243+
.AddQueryType<Query>()
244+
.ModifyOptions(o => o.EnableOneOf = true)
245+
.ExecuteRequestAsync(
246+
OperationRequestBuilder.New()
247+
.SetDocument("query($var: ExampleInput!) { example(input: $var) }")
248+
.SetVariableValues(
249+
new Dictionary<string, object?> { { "var", new ObjectValueNode() } })
250+
.Build())
251+
.MatchSnapshotAsync();
252+
}
253+
108254
[Fact]
109255
public async Task Input_is_set_to_string_abc123_Error()
110256
{
111257
// Error: Incorrect value
112-
113258
await new ServiceCollection()
114259
.AddGraphQL()
115260
.AddQueryType<Query>()
@@ -125,7 +270,6 @@ public async Task Input_is_set_to_string_abc123_Error()
125270
public async Task Var_is_string_abc123_and_passed_to_input_Error()
126271
{
127272
// Error: Incorrect value
128-
129273
await new ServiceCollection()
130274
.AddGraphQL()
131275
.AddQueryType<Query>()
@@ -163,14 +307,36 @@ public async Task B_is_set_to_string_Error()
163307
}
164308

165309
[Fact]
166-
public async Task A_is_set_to_string_Error()
310+
public async Task Var_is_object_with_B_set_to_abc_Error()
167311
{
168312
// Error: Incorrect value for member field {b}
169313
await new ServiceCollection()
170314
.AddGraphQL()
171315
.AddQueryType<Query>()
172316
.ModifyOptions(o => o.EnableOneOf = true)
173-
.ExecuteRequestAsync("{ example(input: { a: \"123\" }) }")
317+
.ExecuteRequestAsync(
318+
OperationRequestBuilder.New()
319+
.SetDocument("query($var: ExampleInput!) { example(input: $var) }")
320+
.SetVariableValues(
321+
new Dictionary<string, object?>
322+
{
323+
{
324+
"var",
325+
new ObjectValueNode(new ObjectFieldNode("b", "abc"))
326+
}
327+
})
328+
.Build())
329+
.MatchSnapshotAsync();
330+
}
331+
332+
[Fact]
333+
public async Task A_is_set_to_string_Valid()
334+
{
335+
await new ServiceCollection()
336+
.AddGraphQL()
337+
.AddQueryType<Query>()
338+
.ModifyOptions(o => o.EnableOneOf = true)
339+
.ExecuteRequestAsync("{ example(input: { a: \"abc\" }) }")
174340
.MatchSnapshotAsync();
175341
}
176342

@@ -184,13 +350,13 @@ public async Task B_is_variable_and_var_not_set_Error()
184350
.ModifyOptions(o => o.EnableOneOf = true)
185351
.ExecuteRequestAsync(
186352
OperationRequestBuilder.New()
187-
.SetDocument("query($var: Int!) { example(input: { b: $var }) }")
353+
.SetDocument("query($b: Int!) { example(input: { b: $b }) }")
188354
.Build())
189355
.MatchSnapshotAsync();
190356
}
191357

192358
[Fact]
193-
public async Task Var_is_object_with_field_a_set_to_abc_Valid()
359+
public async Task Var_is_object_with_field_A_set_to_abc_Valid()
194360
{
195361
await new ServiceCollection()
196362
.AddGraphQL()
@@ -219,24 +385,25 @@ public async Task A_is_set_and_B_is_null_Error()
219385
}
220386

221387
[Fact]
222-
public async Task B_is_variable_and_var_is_null_Valid()
388+
public async Task B_is_variable_and_var_is_null_Error()
223389
{
390+
// Error: Value for member field {b} must be non-null
224391
await new ServiceCollection()
225392
.AddGraphQL()
226393
.AddQueryType<Query>()
227394
.ModifyOptions(o => o.EnableOneOf = true)
228395
.ExecuteRequestAsync(
229396
OperationRequestBuilder.New()
230-
.SetDocument("query($var: Int) { example(input: { b: $var }) }")
231-
.SetVariableValues(new Dictionary<string, object?> { { "var", null } })
397+
.SetDocument("query($b: Int) { example(input: { b: $b }) }")
398+
.SetVariableValues(new Dictionary<string, object?> { { "b", null } })
232399
.Build())
233400
.MatchSnapshotAsync();
234401
}
235402

236403
[Fact]
237404
public async Task B_is_set_and_C_is_invalid_prop_Error()
238405
{
239-
// Error: Exactly one key must be specified
406+
// Error: Unexpected field {c}
240407
await new ServiceCollection()
241408
.AddGraphQL()
242409
.AddQueryType<Query>()
@@ -245,6 +412,31 @@ public async Task B_is_set_and_C_is_invalid_prop_Error()
245412
.MatchSnapshotAsync();
246413
}
247414

415+
[Fact]
416+
public async Task Var_is_object_with_fields_B_and_C_set_Error()
417+
{
418+
// Error: Unexpected field {c}
419+
await new ServiceCollection()
420+
.AddGraphQL()
421+
.AddQueryType<Query>()
422+
.ModifyOptions(o => o.EnableOneOf = true)
423+
.ExecuteRequestAsync(
424+
OperationRequestBuilder.New()
425+
.SetDocument("query($var: ExampleInput!) { example(input: $var) }")
426+
.SetVariableValues(
427+
new Dictionary<string, object?>
428+
{
429+
{
430+
"var",
431+
new ObjectValueNode(
432+
new ObjectFieldNode("b", 123),
433+
new ObjectFieldNode("c", "xyz"))
434+
}
435+
})
436+
.Build())
437+
.MatchSnapshotAsync();
438+
}
439+
248440
[Fact]
249441
public void OneOf_Input_Objects_that_is_Valid()
250442
=> ExpectValid(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"errors": [
3+
{
4+
"message": "The OneOf Input Object `ExampleInput` requires that exactly one field must be supplied and that field must not be `null`.",
5+
"locations": [
6+
{
7+
"line": 1,
8+
"column": 18
9+
}
10+
],
11+
"path": [
12+
"example"
13+
],
14+
"extensions": {
15+
"type": "ExampleInput",
16+
"specifiedBy": "https://spec.graphql.org/draft/#sec-OneOf-Input-Objects-Have-Exactly-One-Field",
17+
"rfc": "https://github.com/graphql/graphql-spec/pull/825"
18+
}
19+
}
20+
]
21+
}

src/HotChocolate/Core/test/Types.Tests/Types/__snapshots__/OneOfIntegrationTests.A_is_set_to_string_Error.snap

Lines changed: 0 additions & 5 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"data": {
3+
"example": "a: abc"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"errors": [
3+
{
4+
"message": "The OneOf Input Object `ExampleInput` requires that exactly one field must be supplied and that field must not be `null`.",
5+
"locations": [
6+
{
7+
"line": 1,
8+
"column": 37
9+
}
10+
],
11+
"path": [
12+
"example"
13+
],
14+
"extensions": {
15+
"type": "ExampleInput",
16+
"specifiedBy": "https://spec.graphql.org/draft/#sec-OneOf-Input-Objects-Have-Exactly-One-Field",
17+
"rfc": "https://github.com/graphql/graphql-spec/pull/825"
18+
}
19+
}
20+
]
21+
}

src/HotChocolate/Core/test/Types.Tests/Types/__snapshots__/OneOfIntegrationTests.A_is_variable_and_B_is_set_Error.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
{
1+
{
22
"errors": [
33
{
44
"message": "The OneOf Input Object `ExampleInput` requires that exactly one field must be supplied and that field must not be `null`.",
55
"locations": [
66
{
77
"line": 1,
8-
"column": 39
8+
"column": 37
99
}
1010
],
1111
"path": [

0 commit comments

Comments
 (0)