不要怂,就是干,撸起袖子干!

Commit d9111faf by Grigory Committed by Sushant

fix(validations): empty not null validation message (#7892)

1 parent dd1911eb
......@@ -322,9 +322,7 @@ class InstanceValidator {
if (rawAttribute.allowNull === false && (value === null || value === undefined)) {
const validators = this.modelInstance.validators[field];
const errMsg = validators
? (validators.notNull || {}).msg
: `${field} cannot be null`;
const errMsg = _.get(validators, 'notNull.msg', `${field} cannot be null`);
error = new sequelizeError.ValidationErrorItem(errMsg, 'notNull Violation', field, value);
this.errors.push(error);
}
......
......@@ -299,7 +299,8 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
});
});
});
describe('Pass all paths when validating', () => {
describe('pass all paths when validating', () => {
beforeEach(function() {
const self = this;
const Project = this.sequelize.define('Project', {
......@@ -344,6 +345,42 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
});
});
});
describe('not null schema validation', () => {
beforeEach(function() {
const Project = this.sequelize.define('Project', {
name: {
type: Sequelize.STRING,
allowNull: false,
validate: {
isIn: [['unknown', 'hello', 'test']] // important to be
}
}
});
return this.sequelize.sync({ force: true }).then(() => {
this.Project = Project;
});
});
it('correctly throws an error using create method ', function() {
return this.Project.create({})
.then(() => {
throw new Error('Validation must be failed');
}, () => {
// fail is ok
});
});
it('correctly throws an error using create method with default generated messages', function() {
return this.Project.create({}).catch(err => {
expect(err).to.have.property('name', 'SequelizeValidationError');
expect(err.message).equal('notNull Violation: name cannot be null');
expect(err.errors).to.be.an('array').and.have.length(1);
expect(err.errors[0]).to.have.property('message', 'name cannot be null');
});
});
});
});
it('correctly validates using custom validation methods', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!