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 245ebfb2
authored
Oct 14, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved first validation tests from jasmine to buster
1 parent
29c1ac01
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
254 additions
and
0 deletions
spec/buster-helpers.js
spec/dao.validations.spec.js
spec/buster-helpers.js
View file @
245ebfb
...
@@ -50,6 +50,16 @@ var BusterHelpers = module.exports = {
...
@@ -50,6 +50,16 @@ var BusterHelpers = module.exports = {
})
})
},
},
getTestDialect
:
function
()
{
envDialect
=
process
.
env
.
DIALECT
||
'mysql'
if
(
this
.
getSupportedDialects
().
indexOf
(
envDialect
)
===
-
1
)
{
throw
new
Error
(
'The dialect you have passed is unknown. Did you really mean: '
+
envDialect
)
}
return
envDialect
},
checkMatchForDialects
:
function
(
dialect
,
value
,
expectations
)
{
checkMatchForDialects
:
function
(
dialect
,
value
,
expectations
)
{
if
(
!!
expectations
[
dialect
])
{
if
(
!!
expectations
[
dialect
])
{
expect
(
value
).
toMatch
(
expectations
[
dialect
])
expect
(
value
).
toMatch
(
expectations
[
dialect
])
...
...
spec/dao.validations.spec.js
0 → 100644
View file @
245ebfb
if
(
typeof
require
===
'function'
)
{
const
buster
=
require
(
"buster"
)
,
Sequelize
=
require
(
"../index"
)
,
Helpers
=
require
(
'./buster-helpers'
)
,
dialect
=
Helpers
.
getTestDialect
()
}
buster
.
spec
.
expose
()
describe
(
dialect
,
function
()
{
describe
(
'=>DAO'
,
function
()
{
describe
(
'validations'
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
dialect
:
dialect
,
onComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
done
()
}.
bind
(
this
)
})
})
//- before
var
checks
=
{
is
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"0"
,
pass
:
"a"
},
not
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"a"
,
pass
:
"0"
},
isEmail
:
{
fail
:
"a"
,
pass
:
"abc@abc.com"
}
,
isUrl
:
{
fail
:
"abc"
,
pass
:
"http://abc.com"
}
,
isIP
:
{
fail
:
"abc"
,
pass
:
"129.89.23.1"
}
,
isAlpha
:
{
fail
:
"012"
,
pass
:
"abc"
}
,
isAlphanumeric
:
{
fail
:
"_abc019"
,
pass
:
"abc019"
}
,
isNumeric
:
{
fail
:
"abc"
,
pass
:
"019"
}
,
isInt
:
{
fail
:
"9.2"
,
pass
:
"-9"
}
,
isLowercase
:
{
fail
:
"AB"
,
pass
:
"ab"
}
,
isUppercase
:
{
fail
:
"ab"
,
pass
:
"AB"
}
,
isDecimal
:
{
fail
:
"a"
,
pass
:
"0.2"
}
,
isFloat
:
{
fail
:
"a"
,
pass
:
"9.2"
}
,
notNull
:
{
fail
:
null
,
pass
:
0
}
,
isNull
:
{
fail
:
0
,
pass
:
null
}
,
notEmpty
:
{
fail
:
" "
,
pass
:
"a"
}
,
equals
:
{
spec
:
{
args
:
"bla bla bla"
},
fail
:
"bla"
,
pass
:
"bla bla bla"
}
,
contains
:
{
spec
:
{
args
:
"bla"
},
fail
:
"la"
,
pass
:
"0bla23"
}
,
notContains
:
{
spec
:
{
args
:
"bla"
},
fail
:
"0bla23"
,
pass
:
"la"
}
,
regex
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"0"
,
pass
:
"a"
}
,
notRegex
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"a"
,
pass
:
"0"
}
,
len
:
{
spec
:
{
args
:
[
2
,
4
]
},
fail
:
[
"1"
,
"12345"
],
pass
:
[
"12"
,
"123"
,
"1234"
],
raw
:
true
}
,
isUUID
:
{
spec
:
{
args
:
4
},
fail
:
"f47ac10b-58cc-3372-a567-0e02b2c3d479"
,
pass
:
"f47ac10b-58cc-4372-a567-0e02b2c3d479"
}
,
isDate
:
{
fail
:
"not a date"
,
pass
:
"2011-02-04"
}
,
isAfter
:
{
spec
:
{
args
:
"2011-11-05"
},
fail
:
"2011-11-04"
,
pass
:
"2011-11-05"
}
,
isBefore
:
{
spec
:
{
args
:
"2011-11-05"
},
fail
:
"2011-11-06"
,
pass
:
"2011-11-05"
}
,
isIn
:
{
spec
:
{
args
:
"abcdefghijk"
},
fail
:
"ghik"
,
pass
:
"ghij"
}
,
notIn
:
{
spec
:
{
args
:
"abcdefghijk"
},
fail
:
"ghij"
,
pass
:
"ghik"
}
,
max
:
{
spec
:
{
args
:
23
},
fail
:
"24"
,
pass
:
"23"
}
,
min
:
{
spec
:
{
args
:
23
},
fail
:
"22"
,
pass
:
"23"
}
,
isArray
:
{
fail
:
22
,
pass
:
[
22
]
}
,
isCreditCard
:
{
fail
:
"401288888888188f"
,
pass
:
"4012888888881881"
}
}
for
(
var
validator
in
checks
)
{
if
(
checks
.
hasOwnProperty
(
validator
))
{
var
validatorDetails
=
checks
[
validator
]
if
(
!
validatorDetails
.
hasOwnProperty
(
"raw"
))
{
validatorDetails
.
fail
=
[
validatorDetails
.
fail
]
validatorDetails
.
pass
=
[
validatorDetails
.
pass
]
}
//////////////////////////
// test the error cases //
//////////////////////////
for
(
var
i
=
0
;
i
<
validatorDetails
.
fail
.
length
;
i
++
)
{
var
failingValue
=
validatorDetails
.
fail
[
i
]
it
(
'correctly specifies an instance as invalid using a value of "'
+
failingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
()
{
var
validations
=
{}
,
message
=
validator
+
"("
+
failingValue
+
")"
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
validations
[
validator
]
=
validatorDetails
.
spec
}
else
{
validations
[
validator
]
=
{}
}
validations
[
validator
].
msg
=
message
var
UserFail
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
validations
}
})
var
failingUser
=
UserFail
.
build
({
name
:
failingValue
})
,
errors
=
failingUser
.
validate
()
expect
(
errors
).
not
.
toBeNull
()
expect
(
errors
).
toEqual
({
name
:
[
message
]
})
})
}
////////////////////////////
// test the success cases //
////////////////////////////
for
(
var
j
=
0
;
j
<
validatorDetails
.
pass
.
length
;
j
++
)
{
var
succeedingValue
=
validatorDetails
.
pass
[
j
]
it
(
'correctly specifies an instance as valid using a value of "'
+
succeedingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
()
{
var
validations
=
{}
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
validations
[
validator
]
=
validatorDetails
.
spec
}
else
{
validations
[
validator
]
=
{}
}
validations
[
validator
].
msg
=
validator
+
"("
+
succeedingValue
+
")"
var
UserSuccess
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
validations
}
})
var
successfulUser
=
UserSuccess
.
build
({
name
:
succeedingValue
})
expect
(
successfulUser
.
validate
()).
toBeNull
()
})
}
}
}
})
})
})
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