Skip to content

Commit 6f7f8d5

Browse files
committed
Add test coverage
1 parent 36f44d3 commit 6f7f8d5

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/execution/__tests__/oneof-test.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,30 @@ describe('Execute: Handles OneOf Input Objects', () => {
113113
});
114114
});
115115

116-
it('rejects a bad variable', () => {
116+
it('accepts a good variable with an undefined key', () => {
117+
const query = `
118+
query ($input: TestInputObject!) {
119+
test(input: $input) {
120+
a
121+
b
122+
}
123+
}
124+
`;
125+
const result = executeQuery(query, rootValue, {
126+
input: { a: 'abc', b: undefined },
127+
});
128+
129+
expectJSON(result).toDeepEqual({
130+
data: {
131+
test: {
132+
a: 'abc',
133+
b: null,
134+
},
135+
},
136+
});
137+
});
138+
139+
it('rejects a variable with multiple non-null keys', () => {
117140
const query = `
118141
query ($input: TestInputObject!) {
119142
test(input: $input) {
@@ -136,5 +159,29 @@ describe('Execute: Handles OneOf Input Objects', () => {
136159
],
137160
});
138161
});
162+
163+
it('rejects a variable with multiple nullable keys', () => {
164+
const query = `
165+
query ($input: TestInputObject!) {
166+
test(input: $input) {
167+
a
168+
b
169+
}
170+
}
171+
`;
172+
const result = executeQuery(query, rootValue, {
173+
input: { a: 'abc', b: null },
174+
});
175+
176+
expectJSON(result).toDeepEqual({
177+
errors: [
178+
{
179+
locations: [{ column: 16, line: 2 }],
180+
message:
181+
'Variable "$input" got invalid value { a: "abc", b: null }; Exactly one key must be specified.',
182+
},
183+
],
184+
});
185+
});
139186
});
140187
});

src/type/__tests__/introspection-test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,7 @@ describe('Introspection', () => {
15491549
15501550
type Query {
15511551
someField(someArg: SomeInputObject): String
1552+
anotherField(anotherArg: AnotherInputObject): String
15521553
}
15531554
`);
15541555

src/utilities/__tests__/valueFromAST-test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ describe('valueFromAST', () => {
232232
expectValueFrom('{ a: "abc" }', testOneOfInputObj).to.deep.equal({
233233
a: 'abc',
234234
});
235+
expectValueFrom('{ b: "def" }', testOneOfInputObj).to.deep.equal({
236+
b: 'def',
237+
});
238+
expectValueFrom('{ a: "abc", b: null }', testOneOfInputObj).to.deep.equal(
239+
undefined,
240+
);
235241
expectValueFrom('{ a: null }', testOneOfInputObj).to.equal(undefined);
236242
expectValueFrom('{ a: 1 }', testOneOfInputObj).to.equal(undefined);
237243
expectValueFrom('{ a: "abc", b: "def" }', testOneOfInputObj).to.equal(

0 commit comments

Comments
 (0)