<commit_before>// Copyright 2016, EMC, Inc.
/* jshint node:true */

'use strict';

describe('Redfish Schemas', function () {
    var tv4;
    var redfish;
    var validator;
    var fs;
    var Promise;
    var fromRoot = process.cwd();

    helper.httpServerBefore();

    before(function () {
        redfish = helper.injector.get('Http.Api.Services.Redfish');
        validator = helper.injector.get('Http.Api.Services.Schema');
        Promise = helper.injector.get('Promise');
        fs = Promise.promisifyAll( helper.injector.get('fs') );
        tv4 = require('tv4');
    });

    beforeEach('set up mocks', function () {
        this.sandbox.spy(tv4, "validate");
        this.sandbox.spy(redfish, 'render');
        this.sandbox.spy(validator, 'validate');
    });

    helper.httpServerAfter();

    it('should return valid schemas', function () {

        return helper.request().get('/redfish/v1/Schemas')
            .expect('Content-Type', /^application\/json/)
            .expect(200)
            .expect(function(res) {
                expect(tv4.validate.called).to.be.true;
                expect(validator.validate.called).to.be.true;
                expect(redfish.render.called).to.be.true;
                expect(res.body['<EMAIL>']).to.equal(194);

            });
    });

    it('should return valid AccountService schema information ', function () {

        return helper.request().get('/redfish/v1/Schemas/AccountService.v1_1_0')
            .expect('Content-Type', /^application\/json/)
            .expect(200)
            .expect(function(res) {
                expect(tv4.validate.called).to.be.true;
                expect(validator.validate.called).to.be.true;
                expect(redfish.render.called).to.be.true;
                expect(res.body.Id).to.equal("AccountService.v1_1_0");
                expect(res.body.Location[0].Uri)
                    .to.equal("/redfish/v1/SchemaStore/en/AccountService.v1_1_0" );
            });
    });

    it('should return valid xml schema information ', function () {
        return Promise.resolve()
            .then(function(){
                return fs.readFileAsync(fromRoot + '/static/DSP8010_2016.3/metadata/Bios_v1.xml', 'utf8');
            })
            .then(function(fileContent){
                return helper.request().get('/redfish/v1/Schemas/Bios_v1.xml')
                    .expect('Content-Type', "text/plain; charset=utf-8")
                    .expect(200)
                    .expect(function(res) {
                        expect(res.text).to.equal(fileContent);
                    });
            });

    });

    it('should return invalid xml schema information ', function () {
        return Promise.resolve()
            .then(function(){
                return helper.request().get('/redfish/v1/Schemas/invallid.xml');
            })
            .then(function(done){<commit_msg>Fix redfish schema unit test for RAC-6014<commit_after>// Copyright 2016, EMC, Inc.
/* jshint node:true */

'use strict';

describe('Redfish Schemas', function () {
    var tv4;
    var redfish;
    var validator;
    var fs;
    var Promise;
    var fromRoot = process.cwd();

    helper.httpServerBefore();

    before(function () {
        redfish = helper.injector.get('Http.Api.Services.Redfish');
        validator = helper.injector.get('Http.Api.Services.Schema');
        Promise = helper.injector.get('Promise');
        fs = Promise.promisifyAll( helper.injector.get('fs') );
        tv4 = require('tv4');
    });

    beforeEach('set up mocks', function () {
        this.sandbox.spy(tv4, "validate");
        this.sandbox.spy(redfish, 'render');
        this.sandbox.spy(validator, 'validate');
    });

    helper.httpServerAfter();

    it('should return valid schemas', function () {

        return helper.request().get('/redfish/v1/Schemas')
            .expect('Content-Type', /^application\/json/)
            .expect(200)
            .expect(function(res) {
                expect(tv4.validate.called).to.be.true;
                expect(validator.validate.called).to.be.true;
                expect(redfish.render.called).to.be.true;
                expect(res.body['<EMAIL>']).to.equal(194);

            });
    });

    it('should return valid AccountService schema information ', function () {

        return helper.request().get('/redfish/v1/Schemas/AccountService.v1_1_0')
            .expect('Content-Type', /^application\/json/)
            .expect(200)
            .expect(function(res) {
                expect(tv4.validate.called).to.be.true;
                expect(validator.validate.called).to.be.true;
                expect(redfish.render.called).to.be.true;
                expect(res.body.Id).to.equal("AccountService.v1_1_0");
                expect(res.body.Location[0].Uri)
                    .to.equal("/redfish/v1/SchemaStore/en/AccountService.v1_1_0" );
            });
    });

    it('should return valid xml schema information ', function () {
        return Promise.resolve()
            .then(function(){
                return fs.readFileAsync(fromRoot + '/static/DSP8010_2016.3/metadata/Bios_v1.xml', 'utf8');
            })
            .then(function(fileContent){
                return helper.request().get('/redfish/v1/Schemas/Bios_v1.xml')
                    .expect('Content-Type', "application/xml; charset=utf-8")
                    .expect(200)
                    .expect(function(res) {
                        expect(res.text).to.equal(fileContent);
                    });
            });

    });

    it('should return invalid xml schema information ', function () {
        return Promise.resolve()
            .then(function(){
                return helper.request().get('/redfish/v1/Schemas/invallid.xml');
            })
            .then(function(done){
{'fraction_non_alphanumeric': 0.15060965138244892, 'fraction_numerical': 0.017860209513996222, 'mean_word_length': 1.9473684210526316, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 11}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1873329', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1665, 'n_words': 243}