Skip to content

Commit

Permalink
Update required tests (#6690)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown authored Oct 1, 2021
1 parent f963966 commit 183e378
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 19 deletions.
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 @@ -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 @@ -6,7 +6,6 @@ export const exampleValue = () => '1990-12-31T12:34:56.789Z';
export const exampleValue2 = () => '2000-01-20T00:08:00.000Z';
export const supportsUnique = true;
export const supportsGraphQLIsNonNull = true;
export const skipRequiredTest = true;
export const fieldName = 'lastOnline';

export const getTestFields = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ 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';

// TODO: test the new validation.isRequired

const testModules = globby.sync(`packages/**/src/**/test-fixtures.{js,ts}`, {
absolute: true,
});
Expand Down Expand Up @@ -46,7 +45,7 @@ testModules
fields: {
name: text(),
testField: mod.typeFunction({
isRequired: true,
validation: { isRequired: true },
...(mod.fieldConfig ? mod.fieldConfig(matrixValue) : {}),
}),
},
Expand All @@ -57,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 @@ -70,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 @@ -95,7 +116,7 @@ testModules
expectValidationError(errors, [
{
path: ['updateTest'],
messages: ['Test.testField: Required field "testField" is null or undefined.'],
messages,
},
]);
})
Expand Down

0 comments on commit 183e378

Please sign in to comment.