2016-07-01 18:33:42 +03:00
|
|
|
'use strict';
|
|
|
|
import { SchemaHelper } from './schema-helper.service';
|
2016-10-23 20:18:42 +03:00
|
|
|
import { SpecManager } from '../utils/spec-manager';
|
2016-07-01 18:33:42 +03:00
|
|
|
|
|
|
|
describe('Spec Helper', () => {
|
|
|
|
describe('buildMenuTree method', () => {
|
|
|
|
let suitSchema = {
|
|
|
|
tags: [
|
|
|
|
{name: 'tag1', description: 'info1', 'x-traitTag': true},
|
2016-12-05 19:25:14 +03:00
|
|
|
{name: 'tag2', description: 'info2'},
|
|
|
|
{name: 'tag4', description: 'info2', 'x-displayName': 'Tag Four'}
|
2016-07-01 18:33:42 +03:00
|
|
|
],
|
|
|
|
paths: {
|
|
|
|
test: {
|
|
|
|
put: {
|
|
|
|
tags: ['tag1', 'tag3'],
|
|
|
|
summary: 'test put'
|
|
|
|
},
|
|
|
|
get: {
|
|
|
|
tags: ['tag1', 'tag2'],
|
|
|
|
summary: 'test get'
|
|
|
|
},
|
2016-12-05 19:25:14 +03:00
|
|
|
delete: {
|
|
|
|
tags: ['tag4'],
|
|
|
|
summary: 'test delete'
|
|
|
|
},
|
2016-07-01 18:33:42 +03:00
|
|
|
// no tags
|
|
|
|
post: {
|
|
|
|
summary: 'test post'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let menuTree;
|
|
|
|
let specMgr;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
specMgr = new SpecManager();
|
|
|
|
specMgr._schema = suitSchema;
|
|
|
|
menuTree = SchemaHelper.buildMenuTree(suitSchema);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return instance of Array', () => {
|
|
|
|
menuTree.should.be.instanceof(Array);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return Array with correct number of items', () => {
|
2016-12-05 19:25:14 +03:00
|
|
|
//3 - defined tags, 1 - tag3 and 1 [other] tag for no-tags method
|
|
|
|
menuTree.length.should.be.equal(3 + 1 + 1);
|
2016-07-01 18:33:42 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should append not defined tags to the end of list', () => {
|
2016-12-05 19:25:14 +03:00
|
|
|
let info = menuTree[3];
|
2016-07-01 18:33:42 +03:00
|
|
|
info.name.should.be.equal('tag3');
|
|
|
|
info.methods.length.should.be.equal(1);
|
|
|
|
info.methods[0].summary.should.be.equal('test put');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should append methods without tags to [other] tag', () => {
|
2016-12-05 19:25:14 +03:00
|
|
|
let info = menuTree[4];
|
2016-07-01 18:33:42 +03:00
|
|
|
info.name.should.be.equal('');
|
|
|
|
info.methods.length.should.be.equal(1);
|
|
|
|
info.methods[0].summary.should.be.equal('test post');
|
|
|
|
});
|
|
|
|
|
2016-07-21 13:35:27 +03:00
|
|
|
it('should map x-traitTag to empty section', () => {
|
|
|
|
let info = menuTree[0];
|
|
|
|
info.empty.should.be.true();
|
|
|
|
});
|
|
|
|
|
2016-07-01 18:33:42 +03:00
|
|
|
it('should map x-traitTag to empty methods list', () => {
|
|
|
|
let info = menuTree[0];
|
|
|
|
info.methods.should.be.empty();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('methods for tag should contain valid pointer and summary', () => {
|
|
|
|
for (let entr of menuTree) {
|
|
|
|
let info = entr;
|
|
|
|
info.should.be.an.Object();
|
|
|
|
info.methods.should.be.an.Array();
|
|
|
|
for (let methodInfo of info.methods) {
|
|
|
|
methodInfo.should.have.properties(['pointer', 'summary']);
|
|
|
|
let methSchema = specMgr.byPointer(methodInfo.pointer);
|
|
|
|
expect(methSchema).not.toBeNull();
|
|
|
|
if (methSchema.summary) {
|
|
|
|
methSchema.summary.should.be.equal(methodInfo.summary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-12-05 19:25:14 +03:00
|
|
|
|
|
|
|
it('should use x-displayName to set custom names', () => {
|
|
|
|
let info = menuTree[2];
|
|
|
|
info.id.should.be.equal('tag/tag4');
|
|
|
|
info.name.should.be.equal('Tag Four');
|
|
|
|
});
|
2016-07-01 18:33:42 +03:00
|
|
|
});
|
2016-07-26 14:07:25 +03:00
|
|
|
|
|
|
|
describe('injectors', () => {
|
|
|
|
it('should autodetect type if not-specified', () => {
|
|
|
|
spyOn(console, 'warn').and.stub();
|
|
|
|
let schema = {
|
|
|
|
type: undefined,
|
|
|
|
properties: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaHelper.runInjectors(schema, schema, '#/');
|
|
|
|
schema.type.should.be.equal('object');
|
|
|
|
expect(console.warn).toHaveBeenCalled();
|
|
|
|
(<jasmine.Spy>console.warn).and.callThrough();
|
|
|
|
});
|
|
|
|
});
|
2016-07-01 18:33:42 +03:00
|
|
|
});
|