Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkessler1 committed Apr 8, 2022
1 parent 36f44d3 commit 6f7f8d5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/execution/__tests__/oneof-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,30 @@ describe('Execute: Handles OneOf Input Objects', () => {
});
});

it('rejects a bad variable', () => {
it('accepts a good variable with an undefined key', () => {
const query = `
query ($input: TestInputObject!) {
test(input: $input) {
a
b
}
}
`;
const result = executeQuery(query, rootValue, {
input: { a: 'abc', b: undefined },
});

expectJSON(result).toDeepEqual({
data: {
test: {
a: 'abc',
b: null,
},
},
});
});

it('rejects a variable with multiple non-null keys', () => {
const query = `
query ($input: TestInputObject!) {
test(input: $input) {
Expand All @@ -136,5 +159,29 @@ describe('Execute: Handles OneOf Input Objects', () => {
],
});
});

it('rejects a variable with multiple nullable keys', () => {
const query = `
query ($input: TestInputObject!) {
test(input: $input) {
a
b
}
}
`;
const result = executeQuery(query, rootValue, {
input: { a: 'abc', b: null },
});

expectJSON(result).toDeepEqual({
errors: [
{
locations: [{ column: 16, line: 2 }],
message:
'Variable "$input" got invalid value { a: "abc", b: null }; Exactly one key must be specified.',
},
],
});
});
});
});
1 change: 1 addition & 0 deletions src/type/__tests__/introspection-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,7 @@ describe('Introspection', () => {
type Query {
someField(someArg: SomeInputObject): String
anotherField(anotherArg: AnotherInputObject): String
}
`);

Expand Down
6 changes: 6 additions & 0 deletions src/utilities/__tests__/valueFromAST-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ describe('valueFromAST', () => {
expectValueFrom('{ a: "abc" }', testOneOfInputObj).to.deep.equal({
a: 'abc',
});
expectValueFrom('{ b: "def" }', testOneOfInputObj).to.deep.equal({
b: 'def',
});
expectValueFrom('{ a: "abc", b: null }', testOneOfInputObj).to.deep.equal(
undefined,
);
expectValueFrom('{ a: null }', testOneOfInputObj).to.equal(undefined);
expectValueFrom('{ a: 1 }', testOneOfInputObj).to.equal(undefined);
expectValueFrom('{ a: "abc", b: "def" }', testOneOfInputObj).to.equal(
Expand Down

0 comments on commit 6f7f8d5

Please sign in to comment.