Skip to content
This repository has been archived by the owner on Apr 7, 2019. It is now read-only.

Commit

Permalink
Main tests added
Browse files Browse the repository at this point in the history
 - version 1.0.0 ready
  • Loading branch information
metric-space committed Jan 7, 2017
1 parent d9965c7 commit 6425b45
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ but that's just me.

1. To provide type validation for entities inside a json object
2. To provide checkif-empty/undefined validation for entities inside a json object
3. The output of this will be a list of errors
3. The output of this will be the first error encountered (Wrapped in a Left) or the whole object (wrapped in a Right)

### Development Goals

1. Use Monads and it's related operations to make for readable code
1. Use Applictive-functors/Monads and it's related operations to make for readable code
2. Use Ramda.js for other other operations
3. Test library thoroughly

Expand Down Expand Up @@ -50,9 +50,12 @@ const incorrect1 = {

validate(incorrect1, schema1);

// output -> [("weapon", undefined), ("pokemon", false), ("material", false)]
// output -> Left("weapon", undefined)
// tuples are based on fantasy-land-tuples

```

### What this is not
1. A fast library (overuse of Ramda.js and Sanctuary js type checking has made this slow)

[![Build Status](https://travis-ci.org/functor-soup/yajjsl.svg?branch=master)](https://travis-ci.org/functor-soup/yajjsl)
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const S = require("sanctuary");
const validate = require("./lib/validate.js").validate;
const validateSchema = require("./lib/schema.js").validateSchema;
const tuples = require('fantasy-tuples'),
Tuple2 = tuples.Tuple2;

function validateComplete(object, schema) {
return validateSchema(schema)
.chain(validate)
return (validateSchema(schema)?
S.Right(schema):
S.Left(Tuple2("Schema","invalid")))
.chain(x => validate(object, x))
.chain(x => S.Right(x));
};

Expand Down
55 changes: 55 additions & 0 deletions tests/test_main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const S = require("sanctuary");
const tuples = require('fantasy-tuples'),
Tuple2 = tuples.Tuple2;
const assert = require("chai").assert;
const validate = require("../index.js").validate;

describe("Util Tests", function() {
it("should return Right given correct schema and schema-valid object",
function() {
const schema1 = {
"weapon": "String",
"pokemon": Tuple2("Array", "String")

};

const object1 = {"weapon" : "sheepinator",
"pokemon":["Blaziken", "Torchic"]}

assert.isTrue(validate(object1, schema1).isRight);

});

it("should return Left given an incorrect schema and schema-valid object",
function() {
const schema1 = {
"weapon": ["Array","Something"],
"pokemon": Tuple2("Array", "String")

};

const object1 = {"weapon" : "sheepinator",
"pokemon":["Blaziken", "Torchic"]}

assert.isTrue(validate(object1, schema1).isLeft);

});

it("should return Left given an correct schema and schema-invalid object",
function() {
const schema1 = {
"weapon": "String",
"pokemon": Tuple2("Array", "String")

};

const object1 = {"weapon" : "sheepinator",
"pokemon":{"name":"Blaziken", "name-ed":"Torchic"}}

assert.isTrue(validate(object1, schema1).isLeft);

});
})



1 change: 0 additions & 1 deletion tests/test_validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ describe("Main validate Util Tests", function() {
it("correct types should output a Right",
function() {
const result = utils.validate(correct, schema1);
console.log(result);
assert.isTrue(result.isRight);

});
Expand Down

0 comments on commit 6425b45

Please sign in to comment.