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 089504fe
authored
Oct 27, 2017
by
Gabe Gorelick
Committed by
Sushant
Oct 27, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(instance-validator): add model name to allowNull messages (#8500)
1 parent
e40f6f45
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
5 deletions
lib/instance-validator.js
test/integration/instance.validations.test.js
test/unit/instance-validator.test.js
lib/instance-validator.js
View file @
089504f
...
@@ -322,7 +322,7 @@ class InstanceValidator {
...
@@ -322,7 +322,7 @@ class InstanceValidator {
if
(
rawAttribute
.
allowNull
===
false
&&
(
value
===
null
||
value
===
undefined
))
{
if
(
rawAttribute
.
allowNull
===
false
&&
(
value
===
null
||
value
===
undefined
))
{
const
validators
=
this
.
modelInstance
.
validators
[
field
];
const
validators
=
this
.
modelInstance
.
validators
[
field
];
const
errMsg
=
_
.
get
(
validators
,
'notNull.msg'
,
`
${
field
}
cannot be null`
);
const
errMsg
=
_
.
get
(
validators
,
'notNull.msg'
,
`
${
this
.
modelInstance
.
constructor
.
name
}
.
${
field
}
cannot be null`
);
error
=
new
sequelizeError
.
ValidationErrorItem
(
errMsg
,
'notNull Violation'
,
field
,
value
);
error
=
new
sequelizeError
.
ValidationErrorItem
(
errMsg
,
'notNull Violation'
,
field
,
value
);
this
.
errors
.
push
(
error
);
this
.
errors
.
push
(
error
);
}
}
...
...
test/integration/instance.validations.test.js
View file @
089504f
...
@@ -299,7 +299,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -299,7 +299,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
});
});
});
});
});
});
describe
(
'pass all paths when validating'
,
()
=>
{
describe
(
'pass all paths when validating'
,
()
=>
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
const
self
=
this
;
const
self
=
this
;
...
@@ -345,7 +345,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -345,7 +345,7 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
});
});
});
});
});
});
describe
(
'not null schema validation'
,
()
=>
{
describe
(
'not null schema validation'
,
()
=>
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
const
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
const
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
...
@@ -375,9 +375,9 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -375,9 +375,9 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
it
(
'correctly throws an error using create method with default generated messages'
,
function
()
{
it
(
'correctly throws an error using create method with default generated messages'
,
function
()
{
return
this
.
Project
.
create
({}).
catch
(
err
=>
{
return
this
.
Project
.
create
({}).
catch
(
err
=>
{
expect
(
err
).
to
.
have
.
property
(
'name'
,
'SequelizeValidationError'
);
expect
(
err
).
to
.
have
.
property
(
'name'
,
'SequelizeValidationError'
);
expect
(
err
.
message
).
equal
(
'notNull Violation: name cannot be null'
);
expect
(
err
.
message
).
equal
(
'notNull Violation:
Project.
name cannot be null'
);
expect
(
err
.
errors
).
to
.
be
.
an
(
'array'
).
and
.
have
.
length
(
1
);
expect
(
err
.
errors
).
to
.
be
.
an
(
'array'
).
and
.
have
.
length
(
1
);
expect
(
err
.
errors
[
0
]).
to
.
have
.
property
(
'message'
,
'name cannot be null'
);
expect
(
err
.
errors
[
0
]).
to
.
have
.
property
(
'message'
,
'
Project.
name cannot be null'
);
});
});
});
});
});
});
...
...
test/unit/instance-validator.test.js
View file @
089504f
...
@@ -65,6 +65,20 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
...
@@ -65,6 +65,20 @@ describe(Support.getTestDialectTeaser('InstanceValidator'), () => {
return
expect
(
result
).
to
.
be
.
rejectedWith
(
SequelizeValidationError
);
return
expect
(
result
).
to
.
be
.
rejectedWith
(
SequelizeValidationError
);
});
});
it
(
'has a useful default error message for not null validation failures'
,
()
=>
{
const
User
=
Support
.
sequelize
.
define
(
'user'
,
{
name
:
{
type
:
Support
.
Sequelize
.
STRING
,
allowNull
:
false
}
});
const
instanceValidator
=
new
InstanceValidator
(
User
.
build
());
const
result
=
instanceValidator
.
validate
();
return
expect
(
result
).
to
.
be
.
rejectedWith
(
SequelizeValidationError
,
/user
\.
name cannot be null/
);
});
});
});
describe
(
'_validateAndRunHooks'
,
()
=>
{
describe
(
'_validateAndRunHooks'
,
()
=>
{
...
...
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