diff --git a/test/class-helper.test.js b/test/class-helper.test.js new file mode 100644 index 0000000..63e88cb --- /dev/null +++ b/test/class-helper.test.js @@ -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'); + }); + }); + }); +}); \ No newline at end of file diff --git a/test/model-helper.test.js b/test/model-helper.test.js index 031bc22..4b6b57a 100644 --- a/test/model-helper.test.js +++ b/test/model-helper.test.js @@ -192,6 +192,36 @@ describe('model-helper', function() { 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. diff --git a/test/route-helper.test.js b/test/route-helper.test.js index f033b39..addd737 100644 --- a/test/route-helper.test.js +++ b/test/route-helper.test.js @@ -73,6 +73,35 @@ describe('route-helper', function() { 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