Skip to content
Snippets Groups Projects
Commit 7df3d9e0 authored by Alvaro Cabrera's avatar Alvaro Cabrera
Browse files

Merge branch 'develop'

parents c2e907e1 1db93753
Branches
Tags
No related merge requests found
...@@ -4,4 +4,5 @@ ...@@ -4,4 +4,5 @@
.DS_Store .DS_Store
/package /package
/reports /reports
/generated
/node_modules /node_modules
...@@ -7,4 +7,5 @@ Gruntfile.js ...@@ -7,4 +7,5 @@ Gruntfile.js
/spec /spec
/package /package
/reports /reports
/generated
/node_modules /node_modules
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
{ {
"name": "json-schema-faker", "name": "json-schema-faker",
"version": "0.1.5", "version": "0.1.6",
"description": "JSON-Schema + Faker", "description": "JSON-Schema + Faker",
"main": "lib/index.js", "main": "lib/index.js",
"author": { "author": {
...@@ -16,15 +16,15 @@ ...@@ -16,15 +16,15 @@
"clone": "^0.1.19", "clone": "^0.1.19",
"glob": "^4.3.5", "glob": "^4.3.5",
"grunt": "^0.4.5", "grunt": "^0.4.5",
"grunt-parts": "^0.3.0", "grunt-parts": "^0.3.1",
"jayschema": "^0.3.1", "jayschema": "^0.3.1",
"semver": "^4.2.0", "semver": "^4.2.0",
"tv4": "^1.1.5", "tv4": "^1.1.9",
"z-schema": "^3.3.1" "z-schema": "^3.3.1"
}, },
"dependencies": { "dependencies": {
"chance": "^0.6.4", "chance": "^0.7.4",
"deref": "^0.2.6", "deref": "^0.2.8",
"faker": "^2.1.2", "faker": "^2.1.2",
"randexp": "^0.4.0" "randexp": "^0.4.0"
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"description": "sub-schema mixins", "description": "sub-schema mixins",
"schemas": [ "schemas": [
{ {
"id": "#",
"type": "object", "type": "object",
"definitions": { "definitions": {
"inner": { "inner": {
......
[
{
"description": "chance issues",
"tests": [
{
"description": "should allow url-format (0.7.1+)",
"schema": {
"type": "string",
"chance": "url"
},
"valid": true
}
]
}
]
...@@ -17,6 +17,23 @@ ...@@ -17,6 +17,23 @@
"format": "semver" "format": "semver"
}, },
"valid": true "valid": true
},
{
"description": "should support faker/chance on numeric types",
"schema": {
"type": "object",
"properties": {
"chanceNumber": {
"type": "integer",
"chance": "natural"
},
"fakerNumber": {
"type": "integer",
"faker": "random.number"
}
}
},
"valid": true
} }
] ]
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{ {
"description": "should handle array of types", "description": "should handle array of types",
"schema": { "schema": {
"type": ["string", "number"] "type": ["string", "integer"]
}, },
"valid": true "valid": true
}, },
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
"schema": { "schema": {
"anyOf": [ "anyOf": [
{ {
"type": "number" "type": "integer"
}, },
{ {
"type": "array" "type": "array"
......
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
"tests": [ "tests": [
{ {
"description": "should handle internal $refs", "description": "should handle internal $refs",
"schema": { "schema": {
"id": "#",
"definitions": { "definitions": {
"number": { "integer": {
"type": "number" "type": "integer"
}, },
"positive": { "positive": {
"minimum": 0, "minimum": 0,
...@@ -17,7 +18,7 @@ ...@@ -17,7 +18,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"weakNumber": { "weakNumber": {
"$ref": "#/definitions/number" "$ref": "#/definitions/integer"
}, },
"multipleOf5": { "multipleOf5": {
"allOf": [ "allOf": [
...@@ -25,7 +26,7 @@ ...@@ -25,7 +26,7 @@
"$ref": "#/definitions/positive" "$ref": "#/definitions/positive"
}, },
{ {
"$ref": "#/definitions/number" "$ref": "#/definitions/integer"
}, },
{ {
"multipleOf": 5 "multipleOf": 5
......
[ [
{ {
"description": "generated number values", "description": "generated integer values",
"tests": [ "tests": [
{ {
"description": "should handle minimum", "description": "should handle minimum",
"schema": { "schema": {
"type": "number", "type": "integer",
"minimum": 10 "minimum": 10
}, },
"hasNot": ".",
"type": "number",
"valid": true "valid": true
}, },
{ {
"description": "should handle maximum", "description": "should handle maximum",
"schema": { "schema": {
"type": "number", "type": "integer",
"minimum": 20, "minimum": 20,
"maximum": 30 "maximum": 30
}, },
"hasNot": ".",
"type": "number",
"valid": true "valid": true
}, },
{ {
"description": "should handle multipleOf", "description": "should handle multipleOf",
"schema": { "schema": {
"type": "number", "type": "integer",
"minimum": 40, "minimum": 40,
"maximum": 50, "maximum": 50,
"multipleOf": 6 "multipleOf": 6
}, },
"hasNot": ".",
"type": "number",
"valid": true "valid": true
}, },
{ {
"description": "should handle exclusiveMinimum", "description": "should handle exclusiveMinimum",
"schema": { "schema": {
"type": "number", "type": "integer",
"minimum": 60, "minimum": 60,
"maximum": 70, "maximum": 70,
"multipleOf": 7, "multipleOf": 7,
"exclusiveMinimum": true "exclusiveMinimum": true
}, },
"hasNot": ".",
"type": "number",
"valid": true "valid": true
}, },
{ {
"description": "should handle exclusiveMaximum", "description": "should handle exclusiveMaximum",
"schema": { "schema": {
"type": "number", "type": "integer",
"minimum": 80, "minimum": 80,
"maximum": 90, "maximum": 90,
"multipleOf": 8, "multipleOf": 8,
"exclusiveMinimum": true, "exclusiveMinimum": true,
"exclusiveMaximum": true "exclusiveMaximum": true
}, },
"hasNot": ".",
"type": "number",
"valid": true "valid": true
}, },
{ {
...@@ -58,7 +68,7 @@ ...@@ -58,7 +68,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"test": { "test": {
"type": "number", "type": "integer",
"minimum": [] "minimum": []
} }
} }
...@@ -71,7 +81,7 @@ ...@@ -71,7 +81,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"test": { "test": {
"type": "number", "type": "integer",
"maximum": [] "maximum": []
} }
} }
...@@ -84,7 +94,7 @@ ...@@ -84,7 +94,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"test": { "test": {
"type": "number", "type": "integer",
"minimum": 100, "minimum": 100,
"maximum": 50 "maximum": 50
} }
......
...@@ -47,7 +47,7 @@ jasmine.Matchers::toHaveSchema = (expected, refs) -> ...@@ -47,7 +47,7 @@ jasmine.Matchers::toHaveSchema = (expected, refs) ->
formatValidators jay formatValidators jay
jay.register(clone(schema), schema.id) for schema in refs if refs jay.register(clone(schema)) for schema in refs if refs
result = jay.validate @actual, clone(expected) result = jay.validate @actual, clone(expected)
......
fs = require('fs') fs = require('fs')
glob = require('glob') glob = require('glob')
deref = require('deref')
jsfaker = require('../lib') jsfaker = require('../lib')
require('./formats').register(jsfaker) require('./formats').register(jsfaker)
...@@ -43,6 +44,9 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) -> ...@@ -43,6 +44,9 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) ->
error = e.message error = e.message
throw e unless test.throws throw e unless test.throws
if test.hasNot
expect(sample.toString()).not.toContain test.hasNot
if test.type if test.type
expect(sample).toHaveType test.type expect(sample).toHaveType test.type
...@@ -50,7 +54,10 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) -> ...@@ -50,7 +54,10 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) ->
expect(error).toMatch new RegExp('^' + test.throws + '$', 'i') expect(error).toMatch new RegExp('^' + test.throws + '$', 'i')
if test.valid if test.valid
schema = deref.util.normalizeSchema(schema)
try try
refs = [schema] if schema.id
expect(sample).toHaveSchema schema, refs expect(sample).toHaveSchema schema, refs
catch e catch e
console.log JSON.stringify(schema, null, 2) console.log JSON.stringify(schema, null, 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment