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 8d6e7160
authored
Mar 07, 2014
by
Thanasis Polychronakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tweak validator tests and add more cases for multiple errors
1 parent
706744aa
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
23 deletions
test/dao.validations.test.js
test/dao.validations.test.js
View file @
8d6e716
...
...
@@ -7,7 +7,7 @@ var chai = require('chai')
chai
.
Assertion
.
includeStack
=
true
describe
(
Support
.
getTestDialectTeaser
(
"DaoValidator"
),
function
()
{
describe
.
only
(
Support
.
getTestDialectTeaser
(
"DaoValidator"
),
function
()
{
describe
(
'validations'
,
function
()
{
var
checks
=
{
is
:
{
...
...
@@ -201,7 +201,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
failingUser
.
validate
().
done
(
function
(
err
,
_errors
)
{
expect
(
_errors
).
to
.
not
.
be
.
null
expect
(
_errors
).
to
.
be
.
an
.
instanceOf
(
Error
);
expect
(
_errors
).
to
.
be
.
an
(
'Object'
);
expect
(
_errors
.
name
).
to
.
deep
.
eql
([
message
])
done
()
})
...
...
@@ -301,7 +301,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
model
.
updateAttributes
({
name
:
''
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
instanceOf
(
Error
)
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
.
name
).
to
.
deep
.
equal
([
'Validation notEmpty failed'
]);
done
()
})
...
...
@@ -323,8 +323,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
Model
.
update
({
name
:
''
},
{
id
:
1
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
instanceOf
(
Error
)
expect
(
err
.
name
).
to
.
deep
.
equal
([
'Validation notEmpty failed'
]);
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
.
name
).
to
.
deep
.
equal
([
'Validation notEmpty failed'
])
done
()
})
})
...
...
@@ -400,8 +400,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
id
:
'helloworld'
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
instanceOf
(
Error
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'Validation isInt failed'
]);
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'Validation isInt failed'
])
done
()
})
})
...
...
@@ -421,8 +421,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'helloworldhelloworld'
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
instanceOf
(
Error
)
expect
(
err
.
username
).
to
.
deep
.
equal
([
'Username must be an integer!'
]);
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
.
username
).
to
.
deep
.
equal
([
'Username must be an integer!'
])
done
()
})
})
...
...
@@ -448,8 +448,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
it
(
'should emit an error when we try to enter in a string for the id key with validation arguments'
,
function
(
done
)
{
this
.
User
.
create
({
id
:
'helloworld'
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
instanceOf
(
Error
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'ID must be an integer!'
]);
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'ID must be an integer!'
])
done
()
})
})
...
...
@@ -458,8 +458,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var
user
=
this
.
User
.
build
({
id
:
'helloworld'
})
user
.
validate
().
success
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
instanceOf
(
Error
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'ID must be an integer!'
]);
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'ID must be an integer!'
])
done
()
})
})
...
...
@@ -467,13 +467,60 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
it
(
'should emit an error when we try to .save()'
,
function
(
done
)
{
var
user
=
this
.
User
.
build
({
id
:
'helloworld'
})
user
.
save
().
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
instanceOf
(
Error
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'ID must be an integer!'
]);
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'ID must be an integer!'
])
done
()
})
})
})
})
describe
(
'Pass all paths when validating'
,
function
()
{
beforeEach
(
function
(
done
)
{
var
self
=
this
var
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
name
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
,
validate
:
{
isIn
:
[[
'unknown'
,
'hello'
,
'test'
]]
}
},
creatorName
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
,
},
cost
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
,
},
})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
something
:
Sequelize
.
INTEGER
})
Project
.
hasOne
(
Task
)
Task
.
hasOne
(
Project
)
Project
.
sync
({
force
:
true
}).
success
(
function
()
{
Task
.
sync
({
force
:
true
}).
success
(
function
()
{
self
.
Project
=
Project
self
.
Task
=
Task
done
()
})
})
})
it
(
'produce 3 errors'
,
function
(
done
)
{
this
.
Project
.
create
({}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
an
(
'Object'
);
expect
(
Object
.
keys
(
err
)).
to
.
have
.
length
(
3
)
done
()
})
})
})
})
it
(
'correctly validates using custom validation methods'
,
function
(
done
)
{
...
...
@@ -495,15 +542,16 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var
failingUser
=
User
.
build
({
name
:
"3"
})
failingUser
.
validate
().
success
(
function
(
error
)
{
expect
(
error
).
to
.
be
.
instanceOf
(
Error
);
expect
(
error
.
name
).
to
.
deep
.
equal
([
"name should equal '2'"
])
expect
(
error
).
to
.
be
.
an
(
'Object'
);
expect
(
error
.
name
[
0
].
message
).
to
.
equal
(
"name should equal '2'"
)
var
successfulUser
=
User
.
build
({
name
:
"2"
})
successfulUser
.
validate
().
success
(
function
()
{
expect
(
arguments
).
to
.
have
.
length
(
0
)
done
()
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
deep
.
equal
({}
)
expect
(
err
[
0
].
message
).
to
.
equal
(
)
done
()
})
})
...
...
@@ -525,7 +573,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
.
validate
()
.
success
(
function
(
error
)
{
expect
(
error
).
not
.
to
.
be
.
null
expect
(
error
).
to
.
be
.
instanceOf
(
Error
);
expect
(
error
).
to
.
be
.
an
(
'Object'
);
expect
(
error
.
age
).
to
.
deep
.
equal
([
"must be positive"
])
User
.
build
({
age
:
null
}).
validate
().
success
(
function
()
{
...
...
@@ -563,8 +611,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
.
validate
()
.
success
(
function
(
error
)
{
expect
(
error
).
not
.
to
.
be
.
null
expect
(
error
).
to
.
be
.
instanceOf
(
Error
)
expect
(
error
.
xnor
).
to
.
deep
.
equal
([
'xnor failed'
]
);
expect
(
error
).
to
.
be
.
an
(
'Object'
)
expect
(
error
.
xnor
[
0
].
message
).
to
.
equal
(
'xnor failed'
);
Foo
.
build
({
field1
:
33
,
field2
:
null
})
...
...
@@ -601,8 +649,8 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
.
validate
()
.
success
(
function
(
error
)
{
expect
(
error
).
not
.
to
.
be
.
null
expect
(
error
).
to
.
be
.
instanceOf
(
Error
)
expect
(
error
.
xnor
).
to
.
deep
.
equal
([
'xnor failed'
]);
expect
(
error
).
to
.
be
.
an
(
'Object'
)
expect
(
error
.
xnor
[
0
].
message
).
to
.
equal
(
'xnor failed'
)
Foo
.
build
({
field1
:
33
,
field2
:
null
})
...
...
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