Permalink
Browse files

Add more tests

  • Loading branch information...
Baggz committed Mar 15, 2012
1 parent a1c0dd1 commit b76eed4f00622671fb87ba8c383c62c237b4843b
Showing with 355 additions and 23 deletions.
  1. +69 −23 tests/json/arrays.js
  2. +286 −0 tests/json/arraysSingleError.js
View
@@ -1,13 +1,20 @@
if (typeof module !== 'undefined' && module.exports) {
var expect = require('expect.js');
- var amanda = require('../../dist/latest.js');
+ var amanda = require('../../releases/latest/amanda.js');
}
/**
* Maximum
* --------------------
*/
-suite('JSON/Arrays', function() {
+suite('JSON/Arrays (without the ‘singleError’ flag)', function() {
+
+ /**
+ * Options
+ */
+ var options = {
+ singleError: false
+ };
/**
* Validator
@@ -28,7 +35,7 @@ suite('JSON/Arrays', function() {
}
};
- jsonSchemaValidator.validate([], schema, function(error) {
+ jsonSchemaValidator.validate([], schema, options, function(error) {
count += 1;
expect(error).to.be(undefined);
});
@@ -38,7 +45,7 @@ suite('JSON/Arrays', function() {
'b',
'c',
'd'
- ], schema, function(error) {
+ ], schema, options, function(error) {
count += 1;
expect(error).to.be(undefined);
});
@@ -48,7 +55,7 @@ suite('JSON/Arrays', function() {
2,
3,
4
- ], schema, function(error) {
+ ], schema, options, function(error) {
count += 1;
@@ -67,7 +74,7 @@ suite('JSON/Arrays', function() {
'b',
'c',
'd'
- ], schema, function(error) {
+ ], schema, options, function(error) {
count += 1;
@@ -86,7 +93,7 @@ suite('JSON/Arrays', function() {
2,
'c',
'd'
- ], schema, function(error) {
+ ], schema, options, function(error) {
count += 1;
@@ -105,7 +112,7 @@ suite('JSON/Arrays', function() {
'b',
3,
'd'
- ], schema, function(error) {
+ ], schema, options, function(error) {
count += 1;
@@ -124,7 +131,7 @@ suite('JSON/Arrays', function() {
'b',
'c',
4
- ], schema, function(error) {
+ ], schema, options, function(error) {
count += 1;
@@ -138,12 +145,38 @@ suite('JSON/Arrays', function() {
});
+ jsonSchemaValidator.validate([
+ 1,
+ 'b',
+ 'c',
+ 4
+ ], schema, options, function(error) {
+
+ count += 1;
+
+ expect(error).to.be.ok();
+ expect(error).to.have.property('0');
+ expect(error).to.have.property('1');
+ expect(error).to.have.property('length', 2);
+
+ expect(error[0]).to.have.property('property', '[0]');
+ expect(error[0]).to.have.property('propertyValue', 1);
+ expect(error[0]).to.have.property('attributeName', 'type');
+ expect(error[0]).to.have.property('attributeValue', 'string');
+
+ expect(error[1]).to.have.property('property', '[3]');
+ expect(error[1]).to.have.property('propertyValue', 4);
+ expect(error[1]).to.have.property('attributeName', 'type');
+ expect(error[1]).to.have.property('attributeValue', 'string');
+
+ });
+
jsonSchemaValidator.validate([
undefined,
undefined,
undefined,
1
- ], schema, function(error) {
+ ], schema, options, function(error) {
count += 1;
@@ -157,7 +190,7 @@ suite('JSON/Arrays', function() {
});
- expect(count).to.be.eql(8);
+ expect(count).to.be.eql(9);
});
@@ -178,22 +211,22 @@ suite('JSON/Arrays', function() {
}
};
- jsonSchemaValidator.validate([], schema, function(error) {
+ jsonSchemaValidator.validate([], schema, options, function(error) {
count += 1;
expect(error).to.be(undefined);
});
- jsonSchemaValidator.validate([[]], schema, function(error) {
+ jsonSchemaValidator.validate([[]], schema, options, function(error) {
count += 1;
expect(error).to.be(undefined);
});
- jsonSchemaValidator.validate([[], []], schema, function(error) {
+ jsonSchemaValidator.validate([[], []], schema, options, function(error) {
count += 1;
expect(error).to.be(undefined);
});
- jsonSchemaValidator.validate([[], undefined, []], schema, function(error) {
+ jsonSchemaValidator.validate([[], undefined, []], schema, options, function(error) {
count += 1;
expect(error).to.be(undefined);
});
@@ -202,7 +235,7 @@ suite('JSON/Arrays', function() {
['a', 'b', 'c', 'd', 'e'],
['a', 'b', 'c', 'd', 'e'],
['a', 'b', 'c', 'd', 'e']
- ], schema, function(error) {
+ ], schema, options, function(error) {
count += 1;
expect(error).to.be(undefined);
});
@@ -211,7 +244,7 @@ suite('JSON/Arrays', function() {
[1, 'b', 'c', 'd', 'e'],
['a', 'b', 'c', 'd', 'e'],
['a', 'b', 'c', 'd', 'e']
- ], schema, function(error) {
+ ], schema, options, function(error) {
count += 1;
@@ -229,7 +262,7 @@ suite('JSON/Arrays', function() {
['a', 'b', 'c', 'd', 'e'],
[1, 'b', 'c', 'd', 'e'],
['a', 'b', 'c', 'd', 'e']
- ], schema, function(error) {
+ ], schema, options, function(error) {
count += 1;
@@ -247,7 +280,7 @@ suite('JSON/Arrays', function() {
['a', 'b', 'c', 'd', 'e'],
['a', 'b', 'c', 'd', 'e'],
[1, 'b', 'c', 'd', 'e']
- ], schema, function(error) {
+ ], schema, options, function(error) {
count += 1;
@@ -262,21 +295,34 @@ suite('JSON/Arrays', function() {
});
jsonSchemaValidator.validate([
- ['a', 'b', 'c', 'd', 'e'],
+ [1, 'b', 'c', 'd', 'e'],
['a', 'b', 1, 'd', 'e'],
- ['a', 'b', 'c', 'd', 'e']
- ], schema, function(error) {
+ ['a', 'b', 'c', 'd', 1]
+ ], schema, options, function(error) {
count += 1;
expect(error).to.be.ok();
expect(error).to.have.property('0');
+ expect(error).to.have.property('1');
+ expect(error).to.have.property('2');
+ expect(error).to.have.property('length', 3);
- expect(error[0]).to.have.property('property', '[1][2]');
+ expect(error[0]).to.have.property('property', '[0][0]');
expect(error[0]).to.have.property('propertyValue', 1);
expect(error[0]).to.have.property('attributeName', 'type');
expect(error[0]).to.have.property('attributeValue', 'string');
+ expect(error[1]).to.have.property('property', '[1][2]');
+ expect(error[1]).to.have.property('propertyValue', 1);
+ expect(error[1]).to.have.property('attributeName', 'type');
+ expect(error[1]).to.have.property('attributeValue', 'string');
+
+ expect(error[2]).to.have.property('property', '[2][4]');
+ expect(error[2]).to.have.property('propertyValue', 1);
+ expect(error[2]).to.have.property('attributeName', 'type');
+ expect(error[2]).to.have.property('attributeValue', 'string');
+
});
expect(count).to.be.eql(9);
Oops, something went wrong.

0 comments on commit b76eed4

Please sign in to comment.