Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit d9111faf
authored
Aug 13, 2017
by
Grigory
Committed by
Sushant
Aug 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(validations): empty not null validation message (#7892)
1 parent
dd1911eb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
4 deletions
lib/instance-validator.js
test/integration/instance.validations.test.js
lib/instance-validator.js
View file @
d9111fa
...
...
@@ -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
);
}
...
...
test/integration/instance.validations.test.js
View file @
d9111fa
...
...
@@ -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
()
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment