-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cc0c96
commit 3a50246
Showing
9 changed files
with
184 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
"use strict"; | ||
|
||
const assert = require("assert"); | ||
const s = require("../"); | ||
|
||
describe("FastBoolean validator", function() { | ||
|
||
it("should require value", function() { | ||
|
||
let schema = s.FastBoolean(); | ||
|
||
assert.throws(function() { | ||
schema.validate(); | ||
}); | ||
|
||
}); | ||
|
||
it("should validate correctly", function() { | ||
|
||
let schema = s.FastBoolean(); | ||
|
||
assert.doesNotThrow(function() { | ||
|
||
schema.validate(true); | ||
schema.validate(false); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
"use strict"; | ||
|
||
const assert = require("assert"); | ||
const s = require("../"); | ||
|
||
describe("FastDate validator", function() { | ||
|
||
const old = new Date("1979"); | ||
const oldString = "1979"; | ||
const older = new Date("1970"); | ||
|
||
it("should require value", function() { | ||
|
||
let schema = s.FastDate(); | ||
|
||
assert.throws(function() { | ||
schema.validate(); | ||
}); | ||
|
||
}); | ||
|
||
it("should accept a valid Date", function() { | ||
let schema = s.FastDate(); | ||
assert.equal(schema.validate(old).getTime(), old.getTime()); | ||
}); | ||
|
||
it("should reject an invalid Date", function() { | ||
let schema = s.FastDate(); | ||
assert.throws(function() { | ||
schema.validate({ dinosaur: "rawwwr" }); | ||
}, Error); | ||
}); | ||
|
||
it("should accept a valid Date as a string", function() { | ||
let schema = s.FastDate(); | ||
assert.equal(schema.validate(oldString).getTime(), old.getTime()); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
"use strict"; | ||
|
||
const assert = require("assert"); | ||
const s = require("../"); | ||
|
||
describe("FastEmail validator", function() { | ||
|
||
it("should require value", function() { | ||
|
||
let schema = s.FastEmail(); | ||
|
||
assert.throws(function() { | ||
schema.validate(); | ||
}); | ||
|
||
}); | ||
|
||
it("should require string", function() { | ||
|
||
let schema = s.FastEmail(); | ||
|
||
assert.throws(function() { | ||
schema.validate(true); | ||
}); | ||
|
||
}); | ||
|
||
it("should accept valid email addresses", function() { | ||
let schema = s.FastEmail(); | ||
let valid = [ | ||
"mel@example.com", | ||
"mel+chickensGoBrrrk@example.com", | ||
"root@127.0.0.1" | ||
]; | ||
let invalid = [ | ||
"notanemailaddress", | ||
"this has spaces @ foo" | ||
]; | ||
valid.forEach(function(e) { | ||
assert.equal(schema.validate(e), e.toLowerCase()); | ||
}); | ||
invalid.forEach(function(e) { | ||
assert.throws(function() { | ||
schema.validate(e); | ||
}, Error); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
"use strict"; | ||
|
||
const assert = require("assert"); | ||
const s = require("../"); | ||
|
||
describe("FastNumber validator", function() { | ||
let small = 2; | ||
let large = 900000000001; | ||
let stringNumber = "123"; | ||
let notANumber = {}; | ||
|
||
it("should require value", function() { | ||
let schema = s.FastNumber(); | ||
assert.throws(function() { | ||
schema.validate(); | ||
}); | ||
}); | ||
|
||
it("should accept a valid Number", function() { | ||
let schema = s.FastNumber(); | ||
assert.equal(schema.validate(small), small); | ||
}); | ||
|
||
it("should reject an invalid Number", function() { | ||
let schema = s.FastNumber(); | ||
assert.throws(function() { | ||
schema.validate(notANumber); | ||
}, Error); | ||
}); | ||
|
||
it("should accept a valid Number as a string", function() { | ||
let schema = s.FastNumber(); | ||
assert.equal(schema.validate(stringNumber), 123); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters