Skip to content

Commit

Permalink
Add a specific test check for filter/order errors (keystonejs#6666)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Sep 28, 2021
1 parent 803ea6e commit 2e95848
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
8 changes: 4 additions & 4 deletions tests/api-tests/queries/filters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
expectAccessReturnError,
expectBadUserInput,
expectGraphQLValidationError,
expectInternalServerError,
expectFilterDenied,
} from '../utils';

const runner = setupTestRunner({
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('isFilterable', () => {
query: '{ users(where: { filterFunctionFalse: { equals: 10 } }) { id } }',
});
expect(body.data).toEqual({ users: null });
expectInternalServerError(body.errors, false, [
expectFilterDenied(body.errors, [
{
path: ['users'],
message:
Expand Down Expand Up @@ -357,7 +357,7 @@ describe('isFilterable', () => {
} ) { id } }`,
});
expect(body.data).toEqual({ secondaryLists: null });
expectInternalServerError(body.errors, false, [
expectFilterDenied(body.errors, [
{
path: ['secondaryLists'],
message:
Expand Down Expand Up @@ -417,7 +417,7 @@ describe('defaultIsFilterable', () => {
query: '{ defaultFilterFunctionFalses(where: { a: { equals: 10 } }) { id } }',
});
expect(body.data).toEqual({ defaultFilterFunctionFalses: null });
expectInternalServerError(body.errors, false, [
expectFilterDenied(body.errors, [
{
path: ['defaultFilterFunctionFalses'],
message:
Expand Down
8 changes: 4 additions & 4 deletions tests/api-tests/queries/orderBy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
expectAccessReturnError,
expectBadUserInput,
expectGraphQLValidationError,
expectInternalServerError,
expectFilterDenied,
} from '../utils';

const runner = setupTestRunner({
Expand Down Expand Up @@ -379,7 +379,7 @@ describe('isOrderable', () => {
query: '{ users(orderBy: [{orderFunctionFalse: asc}]) { id } }',
});
expect(body.data).toEqual({ users: null });
expectInternalServerError(body.errors, false, [
expectFilterDenied(body.errors, [
{
path: ['users'],
message:
Expand Down Expand Up @@ -444,7 +444,7 @@ describe('isOrderable', () => {
'{ users(orderBy: [{orderFunctionTrue: asc}, {orderFunctionFalse: asc}, {orderFunctionFalseToo: asc}]) { id } }',
});
expect(body.data).toEqual({ users: null });
expectInternalServerError(body.errors, false, [
expectFilterDenied(body.errors, [
{
path: ['users'],
message:
Expand Down Expand Up @@ -508,7 +508,7 @@ describe('defaultIsOrderable', () => {
query: '{ defaultOrderFunctionFalses(orderBy: [{a: asc}]) { id } }',
});
expect(body.data).toEqual({ defaultOrderFunctionFalses: null });
expectInternalServerError(body.errors, false, [
expectFilterDenied(body.errors, [
{
path: ['defaultOrderFunctionFalses'],
message:
Expand Down
14 changes: 14 additions & 0 deletions tests/api-tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,17 @@ export const expectRelationshipError = (
}));
expect(unpackedErrors).toEqual(args.map(({ path, message }) => ({ path, message })));
};

export const expectFilterDenied = (
errors: readonly any[] | undefined,
args: { path: any[]; message: string }[]
) => {
const unpackedErrors = unpackErrors(errors);
expect(unpackedErrors).toEqual(
args.map(({ path, message }) => ({
extensions: { code: 'INTERNAL_SERVER_ERROR' },
path,
message,
}))
);
};

0 comments on commit 2e95848

Please sign in to comment.