Skip to content

Commit

Permalink
fix(validations): add prohibitRegexp validation (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
phoebeschmidt authored Jul 19, 2019
1 parent e1fe789 commit bc1d103
Show file tree
Hide file tree
Showing 5 changed files with 1,359 additions and 1,311 deletions.
9 changes: 8 additions & 1 deletion examples/09-validate-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ module.exports = function (migration) {
food.createField('name')
.type('Symbol')
.name('name of the food')
.validations([{ unique: true }]);
.validations([{ unique: true },
{
prohibitRegexp: {
pattern: 'foo',
flags: null
},
message: 'asdf'
}]);

food.createField('calories')
.type('Link')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const regexp = validation('regexp', Joi.object({
flags: Joi.string().allow(null).optional()
}))

const prohibitRegexp = validation('prohibitRegexp', Joi.object({
pattern: Joi.string(),
flags: Joi.string().allow(null).optional()
}))

const unique = validation('unique', Joi.boolean())
const dateRange = validation('dateRange', range('string'))

Expand Down Expand Up @@ -65,6 +70,7 @@ const fieldValidations = Joi.alternatives().try(
size,
rangeValidation,
regexp,
prohibitRegexp,
unique,
dateRange,
assetImageDimensions,
Expand Down
14 changes: 14 additions & 0 deletions test/end-to-end/validations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ describe('apply validations migration examples', function () {
omitted: false,
validations: [{
unique: true
},
{
prohibitRegexp: {
pattern: 'foo',
flags: null
},
message: 'asdf'
}]
},
{
Expand Down Expand Up @@ -88,6 +95,13 @@ describe('apply validations migration examples', function () {
name: 'name of the food',
validations: [{
unique: true
},
{
prohibitRegexp: {
pattern: 'foo',
flags: null
},
message: 'asdf'
}]
}))
.expect(assert.plans.field.create('calories', {
Expand Down
Loading

0 comments on commit bc1d103

Please sign in to comment.