UNPKG

on-http-y1

Version:
122 lines (96 loc) 3.98 kB
// 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(); before('start HTTP server', function () { this.timeout(5000); return helper.startServer([]).then(function () { redfish = helper.injector.get('Http.Api.Services.Redfish'); sinon.spy(redfish, 'render'); validator = helper.injector.get('Http.Api.Services.Schema'); Promise = helper.injector.get('Promise'); fs = Promise.promisifyAll( helper.injector.get('fs') ); sinon.spy(validator, 'validate'); }); }); beforeEach('set up mocks', function () { tv4 = require('tv4'); sinon.spy(tv4, "validate"); validator.validate.reset(); redfish.render.reset(); }); afterEach('tear down mocks', function () { tv4.validate.restore(); }); after('stop HTTP server', function () { validator.validate.restore(); redfish.render.restore(); return helper.stopServer(); }); 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['Members@odata.count']).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){ done(new Error('should have Failed!')); }) .catch(function (e) { expect(e).to.have.property('message');// jshint ignore:line }); }); it('should return 404 on invalid schema information ', function () { return helper.request().get('/redfish/v1/Schemas/AccountService.1.0.01') .expect('Content-Type', /^application\/json/) .expect(404); }); it('should return 404 on invalid schema json', function () { return helper.request().get('/redfish/v1/SchemaStore/en/AccountService.1.0.01') .expect('Content-Type', /^application\/json/) .expect(404); }); });