{"size": 1743, "ext": "js", "max_stars_repo_path": "test/unit/types/schema.test.js", "max_stars_repo_name": "ecomfe/schema-in-js", "max_stars_repo_stars_event_min_datetime": "2017-02-22T06:24:54.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-04T06:51:49.000Z", "max_issues_repo_path": "test/unit/types/schema.test.js", "max_issues_repo_name": "ecomfe/schema-in-js", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/unit/types/schema.test.js", "max_forks_repo_name": "ecomfe/schema-in-js", "max_forks_repo_forks_event_min_datetime": "2017-12-26T03:08:09.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-08T08:29:06.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 26.8153846154, "max_line_length": 83, "alphanum_fraction": 0.5169248422}
/**
 * schema in js
 *
 * @file schema unit test
 * @author hiby(yanghuabei@outlook.com)
 */

import {assert} from 'chai';
import {Schema} from '../../../src/types/schema';
import {ID, REQUIRED, TITLE, DESCRIPTION, DEFAULT, ENUM} from '../../../src/const';

describe('types.schema', function () {
    it('Schema should be a function', function () {
        assert.typeOf(Schema, 'function');
    });

    let schema = new Schema();

    it('Property type should be "null"', function () {
        assert.equal(schema.type, 'null');
    });

    it('Default required should be true', function () {
        assert.equal(schema[REQUIRED], true);
    });

    beforeEach(function () {
        schema = new Schema();
    });

    afterEach(function () {
        schema = null;
    });

    it('Method should work well', function () {
        let values = [];
        let cases = [
            ['id', 'id', ID],
            ['title', 'title', TITLE],
            ['description', 'description', DESCRIPTION],
            ['enum', values, ENUM],
            ['default', null, DEFAULT],
            ['mayBe', false, REQUIRED],
            ['required', false, REQUIRED]
        ];

        cases.forEach(([method, value, property]) => {
            schema[method](value);
            assert.equal(schema[property], value);
        });
    });

    describe('Schema.toJSONSchema', function () {
        it('toJSONSchema method should return expected json schema', function () {
            schema.title('title').desc('desc').mayBe();
            schema = schema.toJSONSchema();
            assert.deepEqual(schema, {
                type: 'null',
                title: 'title',
                description: 'desc'
            });
        });
    });
});
