Skip to content

Commit

Permalink
fix(validations): do not require min and max size validation (#151)
Browse files Browse the repository at this point in the history
Relax migration tool validations for min/max size field validations. Now they are not required, but still nullable.
  • Loading branch information
Phoebe Schmidt authored Nov 28, 2018
1 parent b86df67 commit 99b4976
Show file tree
Hide file tree
Showing 6 changed files with 1,127 additions and 1,136 deletions.
2 changes: 1 addition & 1 deletion examples/09-validate-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ module.exports = function (migration) {
.type('Link')
.linkType('Asset')
.name('amount of calories the food contains')
.validations([{ assetImageDimensions: { width: { min: 1199, max: null }, height: { min: null, max: null } } }]);
.validations([{ assetImageDimensions: { width: { min: 1199, max: null }, height: { min: 1343 } } }]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const validation = (name, constraint) => Joi.object({
})

const range = (type) => Joi.object({
min: Joi[type]().required().allow(null),
max: Joi[type]().required().allow(null)
min: Joi[type]().allow(null),
max: Joi[type]().allow(null)
})

const linkContentType = validation('linkContentType', Joi.array().items(Joi.string()))
Expand Down
11 changes: 2 additions & 9 deletions test/end-to-end/validations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('apply validations migration examples', function () {
disabled: false,
localized: false,
omitted: false,
validations: [{ assetImageDimensions: { width: { min: 1199, max: null }, height: { min: null, max: null } } }]
validations: [{ assetImageDimensions: { width: { min: 1199, max: null }, height: { min: 1343 } } }]
}
];

Expand All @@ -66,19 +66,12 @@ describe('apply validations migration examples', function () {
.on(/\? Do you want to apply the migration \(Y\/n\)/).respond('y\n')
.expect(assert.plans.contentType.create('dieatary-food', { name: 'Dieatary Food', description: 'Food with up to 500 calories' }))
.expect(assert.plans.field.create('name', { type: 'Symbol', name: 'name of the food', validations: [{ unique: true }] }))
.expect(assert.plans.field.create('calories', { type: 'Link', linkType: 'Asset', name: 'amount of calories the food contains', validations: [{ assetImageDimensions: { width: { min: 1199, max: null }, height: { min: null, max: null } } }] }))
.expect(assert.plans.field.create('calories', { type: 'Link', linkType: 'Asset', name: 'amount of calories the food contains', validations: [{ assetImageDimensions: { width: { min: 1199, max: null }, height: { min: 1343 } } }] }))
.expect(assert.plans.actions.apply())
.end(co(function * () {
const contentType = yield getDevContentType(SOURCE_TEST_SPACE, environmentId, 'dieatary-food');
expect(contentType.fields).to.eql(expectedFields);
done();
}));
});

it('attempts to apply 19-bad-validations migration and fails', function (done) {
cli()
.run(`--space-id ${SOURCE_TEST_SPACE} --environment-id ${environmentId} ./examples/19-bad-validations.js`)
.stderr(/The property "validations.0.assetImageDimensions.width.max" is required on the field "assetTest"./)
.end(done);
});
});
Empty file removed test/fixtures/.gitkeep
Empty file.
Loading

0 comments on commit 99b4976

Please sign in to comment.