Skip to content

Commit 301ba6f

Browse files
committed
Add test coverage
1 parent 36f44d3 commit 301ba6f

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/execution/__tests__/oneof-test.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,28 @@ 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, { input: { a: 'abc', b: undefined } });
126+
127+
expectJSON(result).toDeepEqual({
128+
data: {
129+
test: {
130+
a: 'abc',
131+
b: null,
132+
},
133+
},
134+
});
135+
});
136+
137+
it('rejects a variable with multiple non-null keys', () => {
117138
const query = `
118139
query ($input: TestInputObject!) {
119140
test(input: $input) {
@@ -136,5 +157,29 @@ describe('Execute: Handles OneOf Input Objects', () => {
136157
],
137158
});
138159
});
160+
161+
it('rejects a variable with multiple nullable keys', () => {
162+
const query = `
163+
query ($input: TestInputObject!) {
164+
test(input: $input) {
165+
a
166+
b
167+
}
168+
}
169+
`;
170+
const result = executeQuery(query, rootValue, {
171+
input: { a: 'abc', b: null },
172+
});
173+
174+
expectJSON(result).toDeepEqual({
175+
errors: [
176+
{
177+
locations: [{ column: 16, line: 2 }],
178+
message:
179+
'Variable "$input" got invalid value { a: "abc", b: null }; Exactly one key must be specified.',
180+
},
181+
],
182+
});
183+
});
139184
});
140185
});

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ 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(undefined);
235239
expectValueFrom('{ a: null }', testOneOfInputObj).to.equal(undefined);
236240
expectValueFrom('{ a: 1 }', testOneOfInputObj).to.equal(undefined);
237241
expectValueFrom('{ a: "abc", b: "def" }', testOneOfInputObj).to.equal(

0 commit comments

Comments
 (0)