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

fix(validations): add prohibitRegexp validation #201

Merged
merged 1 commit into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
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