Skip to content

Commit

Permalink
Fixed isUnique for DateTime on MongooseAdapter (#3299)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Jul 29, 2020
1 parent acaf19c commit 086b6ba
Show file tree
Hide file tree
Showing 49 changed files with 445 additions and 158 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-balloons-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystonejs/fields': patch
---

Fixed a bug on `MongooseAdapter` where `DateTime` fields did not respect the `isUnique` flag.
13 changes: 13 additions & 0 deletions .changeset/sixty-brooms-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@keystonejs/api-tests': patch
'@keystonejs/field-content': patch
'@keystonejs/fields-authed-relationship': patch
'@keystonejs/fields-auto-increment': patch
'@keystonejs/fields-datetime-utc': patch
'@keystonejs/fields-markdown': patch
'@keystonejs/fields-mongoid': patch
'@keystonejs/fields-wysiwyg-tinymce': patch
'@keystonejs/fields': patch
---

Added more robust checks for support of the `isUnique` flag config. Added tests for this flag.
153 changes: 77 additions & 76 deletions api-tests/required.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,101 +3,102 @@ const { multiAdapterRunners, setupServer, graphqlRequest } = require('@keystonej
const { Text } = require('@keystonejs/fields');

describe('Test isRequired flag for all field types', () => {
const testModules = globby.sync(`packages/fields/src/types/**/test-fixtures.js`, {
absolute: true,
});
const testModules = globby.sync(`packages/**/src/**/test-fixtures.js`, { absolute: true });
multiAdapterRunners().map(({ runner, adapterName }) =>
describe(`Adapter: ${adapterName}`, () => {
testModules.map(require).forEach(mod => {
describe(`Test isRequired flag for module: ${mod.name}`, () => {
const type = mod.type;
const listKey = 'Test';
const keystoneTestWrapper = (testFn = () => {}) =>
runner(
() =>
setupServer({
adapterName,
createLists: keystone => {
if (type.type === 'Select') {
keystone.createList(listKey, {
testModules
.map(require)
.filter(({ skipRequiredTest }) => !skipRequiredTest)
.forEach(mod => {
describe(`Test isRequired flag for module: ${mod.name}`, () => {
const keystoneTestWrapper = testFn =>
runner(
() =>
setupServer({
adapterName,
createLists: keystone => {
keystone.createList('Test', {
fields: {
name: { type: Text },
testField: {
type,
type: mod.type,
isRequired: true,
options: [
{ label: 'Thinkmill', value: 'thinkmill' },
{ label: 'Atlassian', value: 'atlassian' },
],
...(mod.fieldConfig || {}),
},
},
});
} else {
keystone.createList(listKey, {
fields: {
name: { type: Text },
testField: { type, isRequired: true },
},
});
}
},
}),
async ({ keystone, ...rest }) => testFn({ keystone, adapterName, ...rest })
);
test(
'Create an object without the required field',
keystoneTestWrapper(({ keystone }) => {
return graphqlRequest({
keystone,
query: `mutation { createTest(data: { name: "test entry" } ) { id name } }`,
}).then(({ data, errors }) => {
},
}),
testFn
);
test(
'Create an object without the required field',
keystoneTestWrapper(async ({ keystone }) => {
const { data, errors } = await graphqlRequest({
keystone,
query: `
mutation {
createTest(data: { name: "test entry" } ) { id }
}`,
});
expect(data.createTest).toBe(null);
expect(errors).not.toBe(null);
expect(errors.length).toEqual(1);
expect(errors[0].message).toEqual('You attempted to perform an invalid mutation');
expect(errors[0].path[0]).toEqual('createTest');
});
})
);
test(
'Update an object with the required field having a null value',
keystoneTestWrapper(({ keystone }) => {
return graphqlRequest({
keystone,
query: `mutation { createTest(data: { name: "test entry", testField: ${mod.exampleValue} } ) { id name } }`,
}).then(({ data }) => {
return graphqlRequest({
})
);

test(
'Update an object with the required field having a null value',
keystoneTestWrapper(async ({ keystone }) => {
const { data: data0, errors: errors0 } = await graphqlRequest({
keystone,
query: `mutation { updateTest(id: "${data.createTest.id}" data: { name: "updated test entry", testField: null } ) { id name } }`,
}).then(({ data, errors }) => {
expect(data.updateTest).toBe(null);
expect(errors).not.toBe(undefined);
expect(errors.length).toEqual(1);
expect(errors[0].message).toEqual('You attempted to perform an invalid mutation');
expect(errors[0].path[0]).toEqual('updateTest');
query: `
mutation {
createTest(data: { name: "test entry", testField: ${mod.exampleValue} } ) { id }
}`,
});
});
})
);
test(
'Update an object without the required field',
keystoneTestWrapper(({ keystone }) => {
return graphqlRequest({
keystone,
query: `mutation { createTest(data: { name: "test entry", testField: ${mod.exampleValue} } ) { id name } }`,
}).then(({ data }) => {
return graphqlRequest({
expect(errors0).toBe(undefined);
const { data, errors } = await graphqlRequest({
keystone,
query: `mutation { updateTest(id: "${data.createTest.id}" data: { name: "updated test entry" } ) { id name } }`,
}).then(({ data, errors }) => {
expect(data.updateTest).not.toBe(null);
expect(errors).toBe(undefined);
query: `
mutation {
updateTest(id: "${data0.createTest.id}" data: { name: "updated test entry", testField: null } ) { id }
}`,
});
});
})
);
expect(data.updateTest).toBe(null);
expect(errors).not.toBe(undefined);
expect(errors.length).toEqual(1);
expect(errors[0].message).toEqual('You attempted to perform an invalid mutation');
expect(errors[0].path[0]).toEqual('updateTest');
})
);

test(
'Update an object without the required field',
keystoneTestWrapper(async ({ keystone }) => {
const { data: data0, errors: errors0 } = await graphqlRequest({
keystone,
query: `
mutation {
createTest(data: { name: "test entry", testField: ${mod.exampleValue} } ) { id }
}`,
});
expect(errors0).toBe(undefined);
const { data, errors } = await graphqlRequest({
keystone,
query: `
mutation {
updateTest(id: "${data0.createTest.id}" data: { name: "updated test entry" } ) { id }
}`,
});
expect(data.updateTest).not.toBe(null);
expect(errors).toBe(undefined);
})
);
});
});
});
})
);
});
Loading

0 comments on commit 086b6ba

Please sign in to comment.