add more tests
This commit is contained in:
parent
e93d87375b
commit
c001bd6b01
|
@ -0,0 +1,47 @@
|
||||||
|
/**
|
||||||
|
* Created by ytang on 4/7/15.
|
||||||
|
*/
|
||||||
|
var classHelper = require('../lib/class-helper');
|
||||||
|
var loopback = require('loopback');
|
||||||
|
var expect = require('chai').expect;
|
||||||
|
|
||||||
|
describe('class-helper', function() {
|
||||||
|
describe('#generateResourceDocAPIEntry', function() {
|
||||||
|
describe('when ctor.settings.description is an array of string', function() {
|
||||||
|
it('should return description as a string', function() {
|
||||||
|
var aClass = {
|
||||||
|
ctor: {
|
||||||
|
settings: {
|
||||||
|
description: ['1','2','3']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
http:{
|
||||||
|
path: 'path'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = classHelper.generateResourceDocAPIEntry(aClass);
|
||||||
|
expect(result.description).to.eql('123');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when ctor.sharedCtor.description is an array of string', function() {
|
||||||
|
it('should return description as a string', function() {
|
||||||
|
var aClass = {
|
||||||
|
ctor: {
|
||||||
|
settings: {},
|
||||||
|
sharedCtor: {
|
||||||
|
description: ['1','2','3']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
http:{
|
||||||
|
path: 'path'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = classHelper.generateResourceDocAPIEntry(aClass);
|
||||||
|
expect(result.description).to.eql('123');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -192,6 +192,36 @@ describe('model-helper', function() {
|
||||||
expect(def.properties).to.have.property('visibleProperty');
|
expect(def.properties).to.have.property('visibleProperty');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#generateModelDefinition', function(){
|
||||||
|
it('should convert top level array description to string', function(){
|
||||||
|
var model = {};
|
||||||
|
model.definition = {
|
||||||
|
name: 'test',
|
||||||
|
description: ['1','2','3'],
|
||||||
|
properties: {}
|
||||||
|
};
|
||||||
|
var models = {};
|
||||||
|
modelHelper.generateModelDefinition(model, models);
|
||||||
|
expect(models.test.description).to.equal('123');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert property level array description to string', function(){
|
||||||
|
var model = {};
|
||||||
|
model.definition = {
|
||||||
|
name: 'test',
|
||||||
|
properties: {
|
||||||
|
prop1: {
|
||||||
|
type: 'string',
|
||||||
|
description: ['1','2','3']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var models = {};
|
||||||
|
modelHelper.generateModelDefinition(model, models);
|
||||||
|
expect(models.test.properties.prop1.description).to.equal('123');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Simulates the format of a remoting class.
|
// Simulates the format of a remoting class.
|
||||||
|
|
|
@ -73,6 +73,35 @@ describe('route-helper', function() {
|
||||||
expect(opDoc.responseMessages[0].responseModel).to.equal('string');
|
expect(opDoc.responseMessages[0].responseModel).to.equal('string');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#acceptToParameter', function(){
|
||||||
|
it('should return function that converts accepts.description from array of string to string', function(){
|
||||||
|
var f = routeHelper.acceptToParameter({verb: 'get', path: 'path'});
|
||||||
|
var result = f({description: ['1','2','3']});
|
||||||
|
expect(result.description).to.eql('123');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#routeToAPIDoc', function(){
|
||||||
|
it('should convert route.description from array fo string to string', function(){
|
||||||
|
var result = routeHelper.routeToAPIDoc({
|
||||||
|
method: 'someMethod',
|
||||||
|
verb: 'get',
|
||||||
|
path: 'path',
|
||||||
|
description:['1','2','3']
|
||||||
|
});
|
||||||
|
expect(result.operations[0].summary).to.eql('123');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert route.notes from array fo string to string', function(){
|
||||||
|
var result = routeHelper.routeToAPIDoc({
|
||||||
|
method: 'someMethod',
|
||||||
|
verb: 'get',
|
||||||
|
path: 'path',
|
||||||
|
notes:['1','2','3']
|
||||||
|
});
|
||||||
|
expect(result.operations[0].notes).to.eql('123');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Easy wrapper around createRoute
|
// Easy wrapper around createRoute
|
||||||
|
|
Loading…
Reference in New Issue