Skip to content

Commit

Permalink
Add tests for more ID field error code paths (keystonejs#6497)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored and Nikitoring committed Sep 14, 2021
1 parent bd4ce14 commit a3c3bab
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/api-tests/id-field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,64 @@ describe.each(['autoincrement', 'cuid', 'uuid'] as const)('%s', kind => {
]);
})
);
test(
'Fetching an item uniquely with a null id throws an error',
runner(async ({ graphQLRequest }) => {
const { body } = await graphQLRequest({ query: `{ user(where: { id: null}) { id } }` });
expect(body.data).toEqual({ user: null });
expectBadUserInput(body.errors, [
{
path: ['user'],
message: `The unique value provided in a unique where input must not be null`,
},
]);
})
);
test(
'Filtering an item with a null id throws an error',
runner(async ({ graphQLRequest }) => {
const { body } = await graphQLRequest({ query: `{ users(where: { id: null }) { id } }` });
expect(body.data).toEqual({ users: null });
expectBadUserInput(body.errors, [{ path: ['users'], message: `id filter cannot be null` }]);
})
);
test(
'Filtering an item with { equals: null } throws an error',
runner(async ({ graphQLRequest }) => {
const { body } = await graphQLRequest({
query: `{ users(where: { id: { equals: null } }) { id } }`,
});
expect(body.data).toEqual({ users: null });
const s = kind === 'autoincrement' ? 'an integer' : `a ${kind}`;
expectBadUserInput(body.errors, [
{ path: ['users'], message: `Only ${s} can be passed to id filters` },
]);
})
);
test(
'Filtering an item with a in: null throws an error',
runner(async ({ graphQLRequest }) => {
const { body } = await graphQLRequest({
query: `{ users(where: { id: { in: null } }) { id } }`,
});
expect(body.data).toEqual({ users: null });
expectBadUserInput(body.errors, [
{ path: ['users'], message: `in id filter cannot be null` },
]);
})
);
test(
'Filtering an item with a notIn: null throws an error',
runner(async ({ graphQLRequest }) => {
const { body } = await graphQLRequest({
query: `{ users(where: { id: { notIn: null } }) { id } }`,
});
expect(body.data).toEqual({ users: null });
expectBadUserInput(body.errors, [
{ path: ['users'], message: `notIn id filter cannot be null` },
]);
})
);
test(
'Creating an item',
runner(async ({ context }) => {
Expand Down

0 comments on commit a3c3bab

Please sign in to comment.