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

Introduce CRUD testing framework to fix bug in Decimal field #2537

Merged
merged 2 commits into from
Mar 17, 2020
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
Next Next commit
Introduce CRUD testing framework to fix bug in Decimal field
  • Loading branch information
jesstelford committed Mar 17, 2020
commit f212955fa135869316ce2597de251a98068683a7
6 changes: 6 additions & 0 deletions .changeset/funny-pugs-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystonejs/api-tests': patch
'@keystonejs/fields': patch
---

Introduce a framework for testing CRUD operations on fields. This surfaced a bug in the Decimal field where updating _other_ fields would result in a Decimal field being reset to null.
62 changes: 38 additions & 24 deletions api-tests/fields.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,52 @@ const { multiAdapterRunners, setupServer } = require('@keystonejs/test-utils');
// a while, so we bump up the timeout here.
jest.setTimeout(60000);

describe('Test CRUD for all fields', () => {
const testModules = globby.sync(`packages/fields/src/types/**/filterTests.js`, {
describe('Fields', () => {
const testModules = globby.sync(`packages/fields/src/types/**/test-fixtures.js`, {
absolute: true,
});
testModules.push(path.resolve('packages/fields/tests/idFilterTests.js'));
testModules.push(path.resolve('packages/fields/tests/test-fixtures.js'));

multiAdapterRunners().map(({ runner, adapterName }) =>
describe(`Adapter: ${adapterName}`, () => {
describe(`${adapterName} adapter`, () => {
testModules.map(require).forEach(mod => {
describe(`All the CRUD tests for module: ${mod.name}`, () => {
const listName = 'test';
const keystoneTestWrapper = (testFn = () => {}) =>
runner(
() => {
const name = `Field tests for ${mod.name} ${cuid()}`;
const createLists = keystone => {
// Create a list with all the fields required for testing
const fields = mod.getTestFields();
const listName = 'test';
const keystoneTestWrapper = (testFn = () => {}) =>
runner(
() => {
const name = `Field tests for ${mod.name} ${cuid()}`;
const createLists = keystone => {
// Create a list with all the fields required for testing
const fields = mod.getTestFields();

keystone.createList(listName, { fields });
};
return setupServer({ name, adapterName, createLists });
},
async ({ keystone, ...rest }) => {
// Populate the database before running the tests
await keystone.createItems({ [listName]: mod.initItems() });
keystone.createList(listName, { fields });
};
return setupServer({ name, adapterName, createLists });
},
async ({ keystone, ...rest }) => {
// Populate the database before running the tests
await keystone.createItems({ [listName]: mod.initItems() });

return testFn({ keystone, adapterName, ...rest });
}
);
return testFn({ keystone, listName, adapterName, ...rest });
}
);

mod.filterTests(keystoneTestWrapper);
describe(`${mod.name} field`, () => {
if (mod.crudTests) {
describe(`CRUD operations`, () => {
mod.crudTests(keystoneTestWrapper);
});
} else {
test.todo('CRUD operations - tests missing');
}

if (mod.filterTests) {
describe(`Filtering`, () => {
mod.filterTests(keystoneTestWrapper);
});
} else {
test.todo('Filtering - tests missing');
}
});
});
})
Expand Down
2 changes: 1 addition & 1 deletion api-tests/required.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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/**/filterTests.js`, {
const testModules = globby.sync(`packages/fields/src/types/**/test-fixtures.js`, {
absolute: true,
});
multiAdapterRunners().map(({ runner, adapterName }) =>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
"!packages/create-keystone-app/templates/**",
"!packages/core/tests/default-entry/index.js",
"!packages/fields/**/views/**",
"!packages/fields/**/filterTests.js",
"!packages/fields/**/test-fixtures.js",
"!packages/fields/types.js",
"!packages/mongo-join-builder/examples/**"
]
Expand Down
4 changes: 1 addition & 3 deletions packages/fields/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@keystonejs/app-admin-ui": "^5.9.2",
"@keystonejs/build-field-types": "^5.2.2",
"@keystonejs/field-content": "^5.4.3",
"@keystonejs/test-utils": "^5.1.2",
"@keystonejs/utils": "^5.2.2",
"@sindresorhus/slugify": "^0.6.0",
"apollo-errors": "^1.9.0",
Expand Down Expand Up @@ -73,9 +74,6 @@
"slate-react": "^0.22.4",
"unsplash-js": "^6.0.0"
},
"devDependencies": {
"@keystonejs/test-utils": "*"
},
"field-types": {
"entrypoints": [
".",
Expand Down
115 changes: 0 additions & 115 deletions packages/fields/src/types/Decimal/filterTests.js

This file was deleted.

Loading