Coder Social home page Coder Social logo

json-hyper-schema-validator's Introduction

Test runner

This tool validates that a given JSON instance should be VALID (or INVALID) when validated against a JSON Schema (v4 spec, using tv4).

To add tests to the suite:

You should check the folders organization:

{moduleName}
    /{schemaForResourceOrAPIMethod1.json}
    /{schemaForResourceOrAPIMethod2.json}
    /{schemaForResourceOrAPIMethodN.json}
samples/{moduleName}
    /{resourceOrAPIMethod1}
        /validSamples
            /{validSample1.json}
            /{validSampleN.json}
        /invalidSamples
            /{invalidSample1.json}
            /{invalidSampleN.json}
    /{resourceOrAPIMethod2}
        /validSamples
            /{validSample1.json}
            /{validSampleN.json}
        /invalidSamples
            /{invalidSample1.json}
            /{invalidSampleN.json}
    /{resourceOrAPIMethodN}
        /validSamples
            /{validSample1.json}
            /{validSampleN.json}
        /invalidSamples
            /{invalidSample1.json}
            /{invalidSampleN.json}

Where:

  • {moduleName}: Is the name of our API module (like 'SingleSignOn')
  • {resourceOrAPIMethodX}: Is the name for the resource or API method (like 'session' or 'registeruserid')
  • {schemaForResourceOrAPIMethodX.json}: This is the actual JSON Schema (or JSON Hyper Schema), we will have one or mode by {moduleName}, like 'session.json' or 'registeruserid.json'.
  • {validSampleX.json}: This is a sample JSON instance expected to be VALID. There is no restrictions on the file name for this JSON.
  • {invalidSampleX.json}: This is a sample JSON instance expected to be INVALID. There is no restrictions on the file name for this JSON.

So you basically have (for each {moduleName}) a set of instances that should validate against a schema, and another set of instances that should NOT validate against the same schema.

To run the suite:

cd tests
npm install
node suite.js

Here is a sample output:

$ node suite.js 

Running al the tests!
---------------------

Test engine configuration:
{ schemas: '../SinglesignOn/', instances: './samples/SinglesignOn/' }

Done!

Report:
{
    tests: [
        {
            schema: '../SinglesignOn/session.json',
            results: [
                {
                    instance: './samples/SinglesignOn/session/validSamples/sample1.json',
                    shouldBeValid: true,
                    passed: true
                },
                {
                    instance: './samples/SinglesignOn/session/invalidSamples/sample1.json',
                    shouldBeValid: false,
                    passed: false
                }
            ]
        }
    ],
    allTestsPassed: false
}

json-hyper-schema-validator's People

Contributors

raulbajales avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.