Skip to content

Commit a78be5d

Browse files
committed
More tests
1 parent fe65397 commit a78be5d

5 files changed

Lines changed: 351 additions & 1 deletion

File tree

lib/src/test/kotlin/graphql/nadel/validation/NadelStubbedValidationTest.kt

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ class NadelStubbedValidationTest {
10001000
}
10011001

10021002
@Test
1003-
fun `cannot use stubbed enum in non stubbed field`() {
1003+
fun `cannot use stubbed enum as input in non stubbed field`() {
10041004
val fixture = NadelValidationTestFixture(
10051005
overallSchema = mapOf(
10061006
"jira" to """
@@ -1039,6 +1039,129 @@ class NadelStubbedValidationTest {
10391039
assertTrue(error.argument.name == "alphabet")
10401040
}
10411041

1042+
@Test
1043+
fun `can use stubbed enum as input on stubbed field`() {
1044+
val fixture = NadelValidationTestFixture(
1045+
overallSchema = mapOf(
1046+
"jira" to """
1047+
type Query {
1048+
echo: String
1049+
person(alphabet: Alphabet): Person @stubbed
1050+
}
1051+
type Person {
1052+
name: String
1053+
}
1054+
enum Alphabet @stubbed {
1055+
Abc
1056+
Def
1057+
}
1058+
""".trimIndent(),
1059+
),
1060+
underlyingSchema = mapOf(
1061+
"jira" to """
1062+
type Query {
1063+
echo: String
1064+
}
1065+
type Person {
1066+
name: String
1067+
}
1068+
""".trimIndent(),
1069+
),
1070+
)
1071+
1072+
// When
1073+
val errors = validate(fixture)
1074+
1075+
// Then
1076+
assertTrue(errors.isEmpty())
1077+
}
1078+
1079+
@Test
1080+
fun `can use stubbed enum in stubbed input type`() {
1081+
val fixture = NadelValidationTestFixture(
1082+
overallSchema = mapOf(
1083+
"jira" to """
1084+
type Query {
1085+
echo: String
1086+
person(filter: PersonFilter): Person @stubbed
1087+
}
1088+
type Person {
1089+
name: String
1090+
}
1091+
input PersonFilter @stubbed {
1092+
alphabet: Alphabet
1093+
}
1094+
enum Alphabet @stubbed {
1095+
Abc
1096+
Def
1097+
}
1098+
""".trimIndent(),
1099+
),
1100+
underlyingSchema = mapOf(
1101+
"jira" to """
1102+
type Query {
1103+
echo: String
1104+
}
1105+
type Person {
1106+
name: String
1107+
}
1108+
""".trimIndent(),
1109+
),
1110+
)
1111+
1112+
// When
1113+
val errors = validate(fixture)
1114+
1115+
// Then
1116+
assertTrue(errors.isEmpty())
1117+
}
1118+
1119+
@Test
1120+
fun `cannot use stubbed enum in non stubbed input type`() {
1121+
val fixture = NadelValidationTestFixture(
1122+
overallSchema = mapOf(
1123+
"jira" to """
1124+
type Query {
1125+
person(filter: PersonFilter): Person
1126+
}
1127+
type Person {
1128+
name: String
1129+
}
1130+
input PersonFilter {
1131+
alphabet: Alphabet
1132+
}
1133+
enum Alphabet @stubbed {
1134+
Abc
1135+
Def
1136+
}
1137+
""".trimIndent(),
1138+
),
1139+
underlyingSchema = mapOf(
1140+
"jira" to """
1141+
type Query {
1142+
person(filter: PersonFilter): Person
1143+
}
1144+
type Person {
1145+
name: String
1146+
}
1147+
input PersonFilter {
1148+
secret: String
1149+
}
1150+
""".trimIndent(),
1151+
),
1152+
)
1153+
1154+
// When
1155+
val errors = validate(fixture)
1156+
1157+
// Then
1158+
assertTrue(errors.isNotEmpty())
1159+
1160+
val error = errors.assertSingleOfType<NadelSchemaValidationError.MissingUnderlyingInputField>()
1161+
assertTrue(error.parentType.overall.name == "PersonFilter")
1162+
assertTrue(error.overallField.name == "alphabet")
1163+
}
1164+
10421165
@Test
10431166
fun `can use stubbed enum in stubbed type`() {
10441167
val fixture = NadelValidationTestFixture(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package graphql.nadel.tests.next.fixtures.stub
2+
3+
import graphql.nadel.tests.next.NadelIntegrationTest
4+
import java.lang.UnsupportedOperationException
5+
6+
class StubEnumArgumentTest : NadelIntegrationTest(
7+
query = """
8+
{
9+
thing(thing: THING1)
10+
}
11+
""".trimIndent(),
12+
services = listOf(
13+
Service(
14+
name = "myService",
15+
overallSchema = """
16+
type Query {
17+
echo: String
18+
thing(thing: Thing): String @stubbed
19+
}
20+
enum Thing @stubbed {
21+
THING1
22+
THING2
23+
}
24+
""".trimIndent(),
25+
underlyingSchema = """
26+
type Query {
27+
echo: String
28+
}
29+
""".trimIndent(),
30+
runtimeWiring = { wiring ->
31+
data class Issue(
32+
val id: String,
33+
val title: String,
34+
val description: String,
35+
)
36+
wiring
37+
.type("Query") { type ->
38+
type
39+
.dataFetcher("thing") { env ->
40+
throw UnsupportedOperationException()
41+
}
42+
}
43+
},
44+
),
45+
),
46+
)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// @formatter:off
2+
package graphql.nadel.tests.next.fixtures.stub
3+
4+
import graphql.nadel.tests.next.ExpectedNadelResult
5+
import graphql.nadel.tests.next.ExpectedServiceCall
6+
import graphql.nadel.tests.next.TestSnapshot
7+
import graphql.nadel.tests.next.listOfJsonStrings
8+
import kotlin.Suppress
9+
import kotlin.collections.List
10+
import kotlin.collections.listOf
11+
12+
private suspend fun main() {
13+
graphql.nadel.tests.next.update<StubEnumArgumentTest>()
14+
}
15+
16+
/**
17+
* This class is generated. Do NOT modify.
18+
*
19+
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots]
20+
*/
21+
@Suppress("unused")
22+
public class StubEnumArgumentTestSnapshot : TestSnapshot() {
23+
override val calls: List<ExpectedServiceCall> = listOf(
24+
ExpectedServiceCall(
25+
service = "myService",
26+
query = """
27+
| {
28+
| __typename__stubbed__thing: __typename
29+
| }
30+
""".trimMargin(),
31+
variables = "{}",
32+
result = """
33+
| {
34+
| "data": {
35+
| "__typename__stubbed__thing": "Query"
36+
| }
37+
| }
38+
""".trimMargin(),
39+
delayedResults = listOfJsonStrings(
40+
),
41+
),
42+
)
43+
44+
/**
45+
* ```json
46+
* {
47+
* "data": {
48+
* "thing": null
49+
* }
50+
* }
51+
* ```
52+
*/
53+
override val result: ExpectedNadelResult = ExpectedNadelResult(
54+
result = """
55+
| {
56+
| "data": {
57+
| "thing": null
58+
| }
59+
| }
60+
""".trimMargin(),
61+
delayedResults = listOfJsonStrings(
62+
),
63+
)
64+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package graphql.nadel.tests.next.fixtures.stub
2+
3+
import graphql.nadel.tests.next.NadelIntegrationTest
4+
import java.lang.UnsupportedOperationException
5+
6+
class StubEnumInputFieldTest : NadelIntegrationTest(
7+
query = """
8+
{
9+
thing(
10+
filter: {
11+
thing: THING1
12+
}
13+
)
14+
}
15+
""".trimIndent(),
16+
services = listOf(
17+
Service(
18+
name = "myService",
19+
overallSchema = """
20+
type Query {
21+
echo: String
22+
thing(filter: ThingFilter): String @stubbed
23+
}
24+
input ThingFilter @stubbed {
25+
thing: Thing
26+
}
27+
enum Thing @stubbed {
28+
THING1
29+
THING2
30+
}
31+
""".trimIndent(),
32+
underlyingSchema = """
33+
type Query {
34+
echo: String
35+
}
36+
""".trimIndent(),
37+
runtimeWiring = { wiring ->
38+
data class Issue(
39+
val id: String,
40+
val title: String,
41+
val description: String,
42+
)
43+
wiring
44+
.type("Query") { type ->
45+
type
46+
.dataFetcher("thing") { env ->
47+
throw UnsupportedOperationException()
48+
}
49+
}
50+
},
51+
),
52+
),
53+
)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// @formatter:off
2+
package graphql.nadel.tests.next.fixtures.stub
3+
4+
import graphql.nadel.tests.next.ExpectedNadelResult
5+
import graphql.nadel.tests.next.ExpectedServiceCall
6+
import graphql.nadel.tests.next.TestSnapshot
7+
import graphql.nadel.tests.next.listOfJsonStrings
8+
import kotlin.Suppress
9+
import kotlin.collections.List
10+
import kotlin.collections.listOf
11+
12+
private suspend fun main() {
13+
graphql.nadel.tests.next.update<StubEnumInputFieldTest>()
14+
}
15+
16+
/**
17+
* This class is generated. Do NOT modify.
18+
*
19+
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots]
20+
*/
21+
@Suppress("unused")
22+
public class StubEnumInputFieldTestSnapshot : TestSnapshot() {
23+
override val calls: List<ExpectedServiceCall> = listOf(
24+
ExpectedServiceCall(
25+
service = "myService",
26+
query = """
27+
| {
28+
| __typename__stubbed__thing: __typename
29+
| }
30+
""".trimMargin(),
31+
variables = "{}",
32+
result = """
33+
| {
34+
| "data": {
35+
| "__typename__stubbed__thing": "Query"
36+
| }
37+
| }
38+
""".trimMargin(),
39+
delayedResults = listOfJsonStrings(
40+
),
41+
),
42+
)
43+
44+
/**
45+
* ```json
46+
* {
47+
* "data": {
48+
* "thing": null
49+
* }
50+
* }
51+
* ```
52+
*/
53+
override val result: ExpectedNadelResult = ExpectedNadelResult(
54+
result = """
55+
| {
56+
| "data": {
57+
| "thing": null
58+
| }
59+
| }
60+
""".trimMargin(),
61+
delayedResults = listOfJsonStrings(
62+
),
63+
)
64+
}

0 commit comments

Comments
 (0)