Sha256: 95452e02cfbd8fa5277acb5f676576b80183bf857bc06d55c26993730ed0c703

Contents?: true

Size: 1.59 KB

Versions: 11

Compression:

Stored size: 1.59 KB

Contents

'use strict';

const assert = require('assert');
const fs = require('fs');
const Schemas = require('../index.js');
const SchemasFile = require('../resources/js/schemas.js');
const schemaFolder = '../schema/';

describe('Test schemas:', function() {

  describe('Schemas', function() {
    it('should return an object', function() {
      assert.ok(Schemas === Object(Schemas));
    });
  });

  describe('All schemas present', function() {
    it('should return ok', function() {
      fs.readdirSync(__dirname + '/' + schemaFolder).forEach(file => {
        let schema = Schemas[file.split('.')[0]];

        assert.ok(schema === Object(schema));
      });
    });
  });

  describe('ajv', function() {

    const Ajv = require('ajv');
    const data = require('../examples/mdJson.json');
    const ajv = new Ajv({
      extendRefs: 'fail'
    });

    it('should load all schemas', function() {

      ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));

      Object.keys(Schemas).forEach(function(key) {
        let val = Schemas[key];

        ajv.addSchema(val, key);
      });
    });

    it('should validate example', function() {
      ajv.validate('schema', data);
      assert.equal(ajv.errors, null);
    });

    it('should load all schemas from schemas.js file', function() {
      ajv.removeSchema();

      Object.keys(SchemasFile).forEach(function(key) {
        let val = SchemasFile[key];

        ajv.addSchema(val, key);
      });
    });

    it('should validate example again', function() {
      ajv.validate('schema', data);
      assert.equal(ajv.errors, null);
    });
  });

});

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
adiwg-mdjson_schemas-2.4.9 test/test.js
adiwg-mdjson_schemas-2.4.8 test/test.js
adiwg-mdjson_schemas-2.4.7 test/test.js
adiwg-mdjson_schemas-2.4.5 test/test.js
adiwg-mdjson_schemas-2.4.4 test/test.js
adiwg-mdjson_schemas-2.4.3 test/test.js
adiwg-mdjson_schemas-2.4.2 test/test.js
adiwg-mdjson_schemas-2.4.1 test/test.js
adiwg-mdjson_schemas-2.4.0 test/test.js
adiwg-mdjson_schemas-2.3.2 test/test.js
adiwg-mdjson_schemas-2.3.1 test/test.js