Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update required tests #6690

Merged
merged 3 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const exampleValue = () => '6.28';
export const exampleValue2 = () => '6.45';
export const supportsGraphQLIsNonNull = true;
export const supportsUnique = true;
export const skipRequiredTest = true;
export const fieldName = 'price';
export const unSupportedAdapterList = ['sqlite'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const exampleValue = () => '6.28';
export const exampleValue2 = () => '6.45';
export const supportsNullInput = true;
export const supportsUnique = true;
export const skipRequiredTest = true;
export const fieldName = 'price';
export const unSupportedAdapterList = ['sqlite'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const exampleValue = () => 6.28;
export const exampleValue2 = () => 6.283;
export const supportsUnique = true;
export const fieldName = 'testField';
export const skipRequiredTest = true;
export const supportsGraphQLIsNonNull = true;

export const getTestFields = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const exampleValue2 = () => 6.283;
export const supportsNullInput = true;
export const supportsUnique = true;
export const fieldName = 'testField';
export const skipRequiredTest = true;

export const getTestFields = () => ({ testField: float({ isFilterable: true }) });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const exampleValue2 = () => 36;
export const supportsUnique = true;
export const fieldName = 'orderNumber';
export const supportsGraphQLIsNonNull = true;
export const skipRequiredTest = true;
export const skipCreateTest = false;
export const skipUpdateTest = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const exampleValue = () => 37;
export const exampleValue2 = () => 38;
export const supportsGraphQLIsNonNull = true;
export const supportsUnique = true;
export const skipRequiredTest = true;
export const fieldName = 'testField';

export const getTestFields = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const exampleValue = () => 37;
export const exampleValue2 = () => 38;
export const supportsNullInput = true;
export const supportsUnique = true;
export const skipRequiredTest = true;
export const fieldName = 'testField';

export const getTestFields = () => ({ testField: integer({ isFilterable: true }) });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const exampleValue2 = () => 'password2';
export const supportsUnique = false;
export const fieldName = 'password';
export const subfieldName = 'isSet';
export const skipRequiredTest = true;
export const skipCreateTest = true;
export const skipUpdateTest = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const supportsUnique = false;
export const supportsNullInput = true;
export const fieldName = 'password';
export const subfieldName = 'isSet';
export const skipRequiredTest = true;
export const skipCreateTest = true;
export const skipUpdateTest = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export {
supportsUnique,
fieldConfig,
fieldName,
skipRequiredTest,
} from '../test-fixtures';

type MatrixValue = typeof testMatrix[number];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const exampleValue2 = (matrixValue: MatrixValue) =>
matrixValue === 'enum' ? 'atlassian' : matrixValue === 'string' ? '1number' : 2;
export const supportsNullInput = true;
export const supportsUnique = true;
export const skipRequiredTest = true;
export const fieldConfig = (matrixValue: MatrixValue) => {
if (matrixValue === 'enum' || matrixValue === 'string') {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const exampleValue = () => 'foo';
export const exampleValue2 = () => 'bar';
export const supportsNullInput = true;
export const supportsUnique = true;
export const skipRequiredTest = true;
export const fieldName = 'testField';

export const getTestFields = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const exampleValue = () => 'foo';
export const exampleValue2 = () => 'bar';
export const supportsNullInput = false;
export const supportsUnique = true;
export const skipRequiredTest = true;
export const supportsGraphQLIsNonNull = true;
export const fieldName = 'testField';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const exampleValue = () => '1990-12-31T12:34:56.789Z';
export const exampleValue2 = () => '2000-01-20T00:08:00.000Z';
export const supportsNullInput = true;
export const supportsUnique = true;
export const skipRequiredTest = true;
export const fieldName = 'lastOnline';

export const getTestFields = () => ({
Expand Down
29 changes: 26 additions & 3 deletions tests/api-tests/fields/required.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import globby from 'globby';
import { list } from '@keystone-next/keystone';
import { text } from '@keystone-next/keystone/fields';
import { setupTestRunner } from '@keystone-next/keystone/testing';
import { humanize } from '@keystone-next/keystone/src/lib/utils';
import { apiTestConfig, expectValidationError } from '../utils';

const testModules = globby.sync(`packages/**/src/**/test-fixtures.{js,ts}`, {
Expand Down Expand Up @@ -44,7 +45,7 @@ testModules
fields: {
name: text(),
testField: mod.typeFunction({
isRequired: true,
validation: { isRequired: true },
...(mod.fieldConfig ? mod.fieldConfig(matrixValue) : {}),
}),
},
Expand All @@ -55,6 +56,8 @@ testModules
}),
});

const messages = [`Test.testField: ${humanize('testField')} is required`];

test(
'Create an object without the required field',
runner(async ({ context }) => {
Expand All @@ -68,7 +71,27 @@ testModules
expectValidationError(errors, [
{
path: ['createTest'],
messages: ['Test.testField: Required field "testField" is null or undefined.'],
messages:
mod.name === 'Text' ? ['Test.testField: Test Field must not be empty'] : messages,
},
]);
})
);

test(
'Create an object with an explicit null value',
runner(async ({ context }) => {
const { data, errors } = await context.graphql.raw({
query: `
mutation {
createTest(data: { name: "test entry", testField: null } ) { id }
}`,
});
expect(data).toEqual({ createTest: null });
expectValidationError(errors, [
{
path: ['createTest'],
messages,
},
]);
})
Expand All @@ -93,7 +116,7 @@ testModules
expectValidationError(errors, [
{
path: ['updateTest'],
messages: ['Test.testField: Required field "testField" is null or undefined.'],
messages,
},
]);
})
Expand Down