Skip to content

Commit

Permalink
Fixed issue with incorrect date numbers being 01 instead of 1
Browse files Browse the repository at this point in the history
  • Loading branch information
grofit committed Jul 7, 2016
1 parent 80c862a commit 7ff50ca
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion dist/definitions/rules/max-value-validation-rule.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IValidationRule } from "./ivalidation-rule";
export declare class MaxValueValidationRule implements IValidationRule {
ruleName: string;
validate(value: any, maxValue: number | Date): Promise<boolean>;
validate(value: any, maxValue: (number | Date)): Promise<boolean>;
getMessage(value: any, maxValue: any): string;
}
2 changes: 1 addition & 1 deletion dist/definitions/rules/min-value-validation-rule.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IValidationRule } from "./ivalidation-rule";
export declare class MinValueValidationRule implements IValidationRule {
ruleName: string;
validate(value: any, minValue: number | Date): Promise<boolean>;
validate(value: any, minValue: (number | Date)): Promise<boolean>;
getMessage(value: any, minValue: number): string;
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@
"gulp-typedoc": "^2.0.0",
"gulp-typescript": "2.10.0",
"gulp-uglify": "latest",
"karma": "^1.1.0",
"karma": "1.1.0",
"karma-firefox-launcher": "latest",
"karma-mocha": "latest",
"mocha": "latest",
"karma-phantomjs-launcher": "^1.0.0",
"phantomjs-prebuilt": "^2.1.7",
"karma-webpack": "^1.7.0",
"webpack": "^1.4.0",
"karma-webpack": "1.7.0",
"webpack": "1.13.1",
"ts-loader": "0.8.2",
"typescript": "1.8.10",
"merge2": "latest",
"mkdirp": "latest",
"require-dir": "^0.1.0",
"rimraf": "latest",
"typedoc": "^0.3.12",
"ts-loader": "^0.8.0",
"typescript": "^1.8.10"
"typedoc": "^0.3.12"
}
}
4 changes: 2 additions & 2 deletions src/rules/ivalidation-rule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface IValidationRule
{
ruleName: string;
validate(value, options?: any): Promise<boolean>;
getMessage(value, options?: any);
validate(value: any, options?: any): Promise<boolean>;
getMessage(value: any, options?: any);
}
4 changes: 2 additions & 2 deletions src/rules/max-value-validation-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class MaxValueValidationRule implements IValidationRule
{
public ruleName = "maxValue";

public validate(value, maxValue: number|Date): Promise<boolean>
public validate(value: any, maxValue: any): Promise<boolean>
{
if (value === undefined || value === null || value.length == 0)
{ return Promise.resolve(true); }
Expand All @@ -15,7 +15,7 @@ export class MaxValueValidationRule implements IValidationRule
return Promise.resolve(false);
}

public getMessage(value, maxValue) {
public getMessage(value: any, maxValue: any) {
return `This field has a value of ${value} but should be less than or equal to ${maxValue}`;
}
}
4 changes: 2 additions & 2 deletions src/rules/min-value-validation-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class MinValueValidationRule implements IValidationRule
{
public ruleName = "minValue";

public validate(value, minValue: number|Date): Promise<boolean>
public validate(value: any, minValue: any): Promise<boolean>
{
if (value === undefined || value === null || value.length == 0)
{ return Promise.resolve(true); }
Expand All @@ -15,7 +15,7 @@ export class MinValueValidationRule implements IValidationRule
return Promise.resolve(false);
}

public getMessage(value, minValue: number) {
public getMessage(value: any, minValue: any) {
return `This field has a value of ${value} but should be greater than or equal to ${minValue}`;
}
}
9 changes: 4 additions & 5 deletions tests/specs/rules/max-value-rule-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ describe("Validation Rules", function(){

it('should be valid when date is <= max date', function (done) {
var rule = new MaxValueValidationRule();
var maximumDate = new Date(2000, 01, 01);
var validDate = new Date(1990, 01, 01);
var maximumDate = new Date(2000, 1, 1);
var validDate = new Date(1990, 1, 1);
rule.validate(validDate, maximumDate).then(function(isValid){
expect(isValid).to.be.true;
done();
Expand Down Expand Up @@ -60,13 +60,12 @@ describe("Validation Rules", function(){

it('should be invalid when date is > max date', function (done) {
var rule = new MaxValueValidationRule();
var maximumDate = new Date(2000, 01, 01);
var invalidDate = new Date(2001, 01, 01);
var maximumDate = new Date(2000, 1, 1);
var invalidDate = new Date(2001, 1, 1);
rule.validate(invalidDate, maximumDate).then(function(isValid){
expect(isValid).to.be.false;
done();
});
});

});
});
8 changes: 4 additions & 4 deletions tests/specs/rules/min-value-rule-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ describe("Validation Rules", function(){

it('should be valid when date is >= min date', function (done) {
var rule = new MinValueValidationRule();
var minDate = new Date(2000, 01, 01);
var validDate = new Date(2001, 01, 01);
var minDate = new Date(2000, 1, 1);
var validDate = new Date(2001, 1, 1);
rule.validate(validDate, minDate).then(function(isValid){
expect(isValid).to.be.true;
done();
Expand Down Expand Up @@ -60,8 +60,8 @@ describe("Validation Rules", function(){

it('should be invalid when date is < min date', function (done) {
var rule = new MinValueValidationRule();
var minDate = new Date(2000, 01, 01);
var invalidDate = new Date(1990, 01, 01);
var minDate = new Date(2000, 1, 1);
var invalidDate = new Date(1990, 1, 1);
rule.validate(invalidDate, minDate).then(function(isValid){
expect(isValid).to.be.false;
done();
Expand Down
12 changes: 6 additions & 6 deletions tests/specs/ruleset-builder-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Ruleset Builder', function () {

it('should correctly add rules to the ruleset', function () {
var dummyRuleRegistry = { hasRuleNamed: function(){ return true; }};
var rulesetBuilder = new RulesetBuilder(<RuleRegistry>dummyRuleRegistry);
var rulesetBuilder = new RulesetBuilder(<any>dummyRuleRegistry);

var ruleset: any = rulesetBuilder.create()
.forProperty("foo")
Expand All @@ -25,7 +25,7 @@ describe('Ruleset Builder', function () {

it('should support custom message strings on rules added to the ruleset', function () {
var dummyRuleRegistry = { hasRuleNamed: function(){ return true; }};
var rulesetBuilder = new RulesetBuilder(<RuleRegistry>dummyRuleRegistry);
var rulesetBuilder = new RulesetBuilder(<any>dummyRuleRegistry);

var ruleset: any = rulesetBuilder.create()
.forProperty("foo")
Expand All @@ -41,7 +41,7 @@ describe('Ruleset Builder', function () {

it('should support custom message functions on rules added to the ruleset', function () {
var dummyRuleRegistry = { hasRuleNamed: function(){ return true; }};
var rulesetBuilder = new RulesetBuilder(<RuleRegistry>dummyRuleRegistry);
var rulesetBuilder = new RulesetBuilder(<any>dummyRuleRegistry);

var ruleset: any = rulesetBuilder.create()
.forProperty("foo")
Expand All @@ -57,7 +57,7 @@ describe('Ruleset Builder', function () {

it('should correctly add rulesets to properties in the generated ruleset', function () {
var dummyRuleRegistry = { hasRuleNamed: function(){ return true; }};
var rulesetBuilder = new RulesetBuilder(<RuleRegistry>dummyRuleRegistry);
var rulesetBuilder = new RulesetBuilder(<any>dummyRuleRegistry);

var dummyRuleset: any = new Ruleset();
dummyRuleset.rules.bar = [ new RuleLink("required", true) ];
Expand All @@ -75,7 +75,7 @@ describe('Ruleset Builder', function () {

it('should correctly add foreach rules to the ruleset', function () {
var dummyRuleRegistry = { hasRuleNamed: function(){ return true; }};
var rulesetBuilder = new RulesetBuilder(<RuleRegistry>dummyRuleRegistry);
var rulesetBuilder = new RulesetBuilder(<any>dummyRuleRegistry);

var ruleset: any = rulesetBuilder.create()
.forProperty("foo")
Expand All @@ -90,7 +90,7 @@ describe('Ruleset Builder', function () {

it('should not allow empty rule names with ruleRegistry', function () {
var dummyRuleRegistry = { hasRuleNamed: function(){ return true; }};
var rulesetBuilder = new RulesetBuilder(<RuleRegistry>dummyRuleRegistry);
var rulesetBuilder = new RulesetBuilder(<any>dummyRuleRegistry);
var hasFailed = false;

try
Expand Down
8 changes: 4 additions & 4 deletions tests/specs/validation-group-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Validation Group', function () {
it('should correctly get errors', function (done) {

var dummyRuleRegistry = { hasRuleNamed: function(){ return true; }};
var rulesetBuilder = new RulesetBuilder(<RuleRegistry>dummyRuleRegistry);
var rulesetBuilder = new RulesetBuilder(<any>dummyRuleRegistry);
var ruleset = rulesetBuilder.create()
.forProperty("foo")
.addRule("maxLength", 2)
Expand Down Expand Up @@ -545,7 +545,7 @@ describe('Validation Group', function () {
it('should only return errors when all validation events have finished', function (done) {

// This basically delays validation so others stack
var delayedRequiresValid = {
var delayedRequiresValid: any = {
ruleName: "delayed",
validate: function(value, options){
return new Promise(function(resolve, reject){
Expand Down Expand Up @@ -581,7 +581,7 @@ describe('Validation Group', function () {

it('should only return valid state when all validation events have finished', function (done) {

var delayedRequiresValid = {
var delayedRequiresValid: any = {
ruleName: "delayed",
validate: function(value, options){
return new Promise(function(resolve, reject){
Expand Down Expand Up @@ -617,7 +617,7 @@ describe('Validation Group', function () {

it('should correctly delay error requests until validation has finished', function (done) {

var delayedRequires10Rule = {
var delayedRequires10Rule: any = {
ruleName: "delayed",
validate: function(value, options){
return new Promise(function(resolve, reject){
Expand Down

0 comments on commit 7ff50ca

Please sign in to comment.