mirror of
https://github.com/Redocly/redoc.git
synced 2025-06-25 07:03:02 +03:00
Sort tests by groups
This commit is contained in:
parent
b06ac81937
commit
53f7f3a007
|
@ -12,55 +12,56 @@ import {
|
||||||
|
|
||||||
import {Tabs, Tab} from 'lib/common/components/Tabs/tabs';
|
import {Tabs, Tab} from 'lib/common/components/Tabs/tabs';
|
||||||
|
|
||||||
|
describe('Common components', () => {
|
||||||
|
describe('Tabs Component', () => {
|
||||||
|
let builder;
|
||||||
|
let component;
|
||||||
|
let nativeElement;
|
||||||
|
let childDebugEls;
|
||||||
|
let fixture;
|
||||||
|
|
||||||
describe('Tabs Component', () => {
|
beforeEach(inject([TestComponentBuilder], (tcb) => {
|
||||||
let builder;
|
builder = tcb;
|
||||||
let component;
|
}));
|
||||||
let nativeElement;
|
beforeEach((done) => {
|
||||||
let childDebugEls;
|
builder.createAsync(TestApp).then(_fixture => {
|
||||||
let fixture;
|
fixture = _fixture;
|
||||||
|
let debugEl = getChildDebugElement(fixture.debugElement, 'tabs');
|
||||||
beforeEach(inject([TestComponentBuilder], (tcb) => {
|
childDebugEls = getChildDebugElementAll(debugEl, 'tab');
|
||||||
builder = tcb;
|
component = debugEl.componentInstance;
|
||||||
}));
|
nativeElement = debugEl.nativeElement;
|
||||||
beforeEach((done) => {
|
done();
|
||||||
builder.createAsync(TestApp).then(_fixture => {
|
}, err => done.fail(err));
|
||||||
fixture = _fixture;
|
});
|
||||||
let debugEl = getChildDebugElement(fixture.debugElement, 'tabs');
|
|
||||||
childDebugEls = getChildDebugElementAll(debugEl, 'tab');
|
|
||||||
component = debugEl.componentInstance;
|
|
||||||
nativeElement = debugEl.nativeElement;
|
|
||||||
done();
|
|
||||||
}, err => done.fail(err));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should init component', () => {
|
it('should init component', () => {
|
||||||
expect(component).not.toBeNull();
|
expect(component).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle inner tabs', () => {
|
it('should handle inner tabs', () => {
|
||||||
component.tabs.should.have.lengthOf(2);
|
component.tabs.should.have.lengthOf(2);
|
||||||
childDebugEls.should.have.lengthOf(2);
|
childDebugEls.should.have.lengthOf(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should activate first tab by default', () => {
|
it('should activate first tab by default', () => {
|
||||||
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
|
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
|
||||||
let [tab1, tab2] = tabs;
|
let [tab1, tab2] = tabs;
|
||||||
|
|
||||||
tab1.active.should.be.true;
|
tab1.active.should.be.true;
|
||||||
tab2.active.should.be.false;
|
tab2.active.should.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should change active tab on click', () => {
|
it('should change active tab on click', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let headerEls = nativeElement.querySelectorAll('li');
|
let headerEls = nativeElement.querySelectorAll('li');
|
||||||
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
|
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
|
||||||
let [tab1, tab2] = tabs;
|
let [tab1, tab2] = tabs;
|
||||||
|
|
||||||
mouseclick(headerEls[0]);
|
mouseclick(headerEls[0]);
|
||||||
tab1.active.should.be.false;
|
tab1.active.should.be.false;
|
||||||
tab2.active.should.be.true;
|
tab2.active.should.be.true;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -12,82 +12,83 @@ import {
|
||||||
|
|
||||||
import Zippy from 'lib/common/components/Zippy/zippy';
|
import Zippy from 'lib/common/components/Zippy/zippy';
|
||||||
|
|
||||||
|
describe('Common components', () => {
|
||||||
|
describe('Zippy Component', () => {
|
||||||
|
let builder;
|
||||||
|
let component;
|
||||||
|
let nativeElement;
|
||||||
|
let fixture;
|
||||||
|
|
||||||
describe('Zippy Component', () => {
|
beforeEach(inject([TestComponentBuilder], (tcb) => {
|
||||||
let builder;
|
builder = tcb;
|
||||||
let component;
|
}));
|
||||||
let nativeElement;
|
beforeEach((done) => {
|
||||||
let fixture;
|
builder.createAsync(TestApp).then(_fixture => {
|
||||||
|
fixture = _fixture;
|
||||||
beforeEach(inject([TestComponentBuilder], (tcb) => {
|
let debugEl = getChildDebugElement(fixture.debugElement, 'zippy');
|
||||||
builder = tcb;
|
component = debugEl.componentInstance;
|
||||||
}));
|
nativeElement = debugEl.nativeElement;
|
||||||
beforeEach((done) => {
|
done();
|
||||||
builder.createAsync(TestApp).then(_fixture => {
|
}, err => done.fail(err));
|
||||||
fixture = _fixture;
|
});
|
||||||
let debugEl = getChildDebugElement(fixture.debugElement, 'zippy');
|
|
||||||
component = debugEl.componentInstance;
|
|
||||||
nativeElement = debugEl.nativeElement;
|
|
||||||
done();
|
|
||||||
}, err => done.fail(err));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should init component', () => {
|
it('should init component', () => {
|
||||||
expect(component).not.toBeNull();
|
expect(component).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should init component defaults', () => {
|
it('should init component defaults', () => {
|
||||||
component.empty.should.be.false;
|
component.empty.should.be.false;
|
||||||
component.visible.should.be.false;
|
component.visible.should.be.false;
|
||||||
component.type.should.be.equal('general');
|
component.type.should.be.equal('general');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should init properties from dom params', () => {
|
it('should init properties from dom params', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.visible.should.be.true;
|
component.visible.should.be.true;
|
||||||
component.empty.should.be.true;
|
component.empty.should.be.true;
|
||||||
component.title.should.be.equal('Zippy');
|
component.title.should.be.equal('Zippy');
|
||||||
component.type.should.be.equal('test');
|
component.type.should.be.equal('test');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('project inner content', () => {
|
it('project inner content', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let contentEl = nativeElement.querySelector('.zippy-content');
|
let contentEl = nativeElement.querySelector('.zippy-content');
|
||||||
expect(contentEl).toHaveText('\n test\n ');
|
expect(contentEl).toHaveText('\n test\n ');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should open and close zippy', () => {
|
it('should open and close zippy', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.empty = false;
|
component.empty = false;
|
||||||
component.visible = true;
|
component.visible = true;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
let testComponent = fixture.debugElement.componentInstance;
|
let testComponent = fixture.debugElement.componentInstance;
|
||||||
|
|
||||||
let titleEl = nativeElement.querySelector('.zippy-title');
|
let titleEl = nativeElement.querySelector('.zippy-title');
|
||||||
mouseclick(titleEl);
|
mouseclick(titleEl);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.visible.should.be.false;
|
component.visible.should.be.false;
|
||||||
testComponent.opened.should.be.false;
|
testComponent.opened.should.be.false;
|
||||||
|
|
||||||
mouseclick(titleEl);
|
mouseclick(titleEl);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.visible.should.be.true;
|
component.visible.should.be.true;
|
||||||
testComponent.opened.should.be.true;
|
testComponent.opened.should.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should disable empty zippy', () => {
|
it('should disable empty zippy', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.empty = true;
|
component.empty = true;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
let testComponent = fixture.debugElement.componentInstance;
|
let testComponent = fixture.debugElement.componentInstance;
|
||||||
|
|
||||||
let titleEl = nativeElement.querySelector('.zippy-title');
|
let titleEl = nativeElement.querySelector('.zippy-title');
|
||||||
mouseclick(titleEl);
|
mouseclick(titleEl);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
testComponent.clickCount.should.be.equal(0);
|
testComponent.clickCount.should.be.equal(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -15,37 +15,39 @@ import ApiInfo from 'lib/components/ApiInfo/api-info';
|
||||||
import SchemaManager from 'lib/utils/SchemaManager';
|
import SchemaManager from 'lib/utils/SchemaManager';
|
||||||
|
|
||||||
|
|
||||||
describe('ApiInfo Component', () => {
|
describe('Redoc components', () => {
|
||||||
let builder;
|
describe('ApiInfo Component', () => {
|
||||||
let component;
|
let builder;
|
||||||
let fixture;
|
let component;
|
||||||
beforeEachProviders(() => [
|
let fixture;
|
||||||
provide(SchemaManager, {useValue: new SchemaManager()})
|
beforeEachProviders(() => [
|
||||||
]);
|
provide(SchemaManager, {useValue: new SchemaManager()})
|
||||||
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
]);
|
||||||
builder = tcb;
|
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||||
return schemaMgr.load('/tests/schemas/api-info-test.json').then(() => null, (err) => { throw err; });
|
builder = tcb;
|
||||||
}));
|
return schemaMgr.load('/tests/schemas/api-info-test.json').then(() => null, (err) => { throw err; });
|
||||||
beforeEach((done) => {
|
}));
|
||||||
builder.createAsync(TestApp).then(_fixture => {
|
beforeEach((done) => {
|
||||||
fixture = _fixture;
|
builder.createAsync(TestApp).then(_fixture => {
|
||||||
component = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance;
|
fixture = _fixture;
|
||||||
fixture.detectChanges();
|
component = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance;
|
||||||
done();
|
fixture.detectChanges();
|
||||||
}, err => done.fail(err));
|
done();
|
||||||
});
|
}, err => done.fail(err));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('shold init component data', () => {
|
it('shold init component data', () => {
|
||||||
expect(component).not.toBeNull();
|
expect(component).not.toBeNull();
|
||||||
expect(component.data).not.toBeNull();
|
expect(component.data).not.toBeNull();
|
||||||
component.data.title.should.be.equal('Swagger Petstore');
|
component.data.title.should.be.equal('Swagger Petstore');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shold render api name and version', () => {
|
it('shold render api name and version', () => {
|
||||||
let nativeElement = getChildDebugElement(fixture.debugElement, 'api-info').nativeElement;
|
let nativeElement = getChildDebugElement(fixture.debugElement, 'api-info').nativeElement;
|
||||||
let headerElement = nativeElement.querySelector('h1');
|
let headerElement = nativeElement.querySelector('h1');
|
||||||
expect(headerElement).toHaveText('Swagger Petstore (1.0.0)');
|
expect(headerElement).toHaveText('Swagger Petstore (1.0.0)');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,39 +14,40 @@ import {
|
||||||
import Method from 'lib/components/Method/method';
|
import Method from 'lib/components/Method/method';
|
||||||
import SchemaManager from 'lib/utils/SchemaManager';
|
import SchemaManager from 'lib/utils/SchemaManager';
|
||||||
|
|
||||||
|
describe('Redoc components', () => {
|
||||||
describe('Method Component', () => {
|
describe('Method Component', () => {
|
||||||
let builder;
|
let builder;
|
||||||
let component;
|
let component;
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
provide(SchemaManager, {useValue: new SchemaManager()})
|
provide(SchemaManager, {useValue: new SchemaManager()})
|
||||||
]);
|
]);
|
||||||
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||||
builder = tcb;
|
builder = tcb;
|
||||||
return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; });
|
return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; });
|
||||||
}));
|
}));
|
||||||
beforeEach((done) => {
|
beforeEach((done) => {
|
||||||
builder.createAsync(TestApp).then(fixture => {
|
builder.createAsync(TestApp).then(fixture => {
|
||||||
component = getChildDebugElement(fixture.debugElement, 'method').componentInstance;
|
component = getChildDebugElement(fixture.debugElement, 'method').componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
done();
|
done();
|
||||||
}, err => done.fail(err));
|
}, err => done.fail(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should init component', () => {
|
it('should init component', () => {
|
||||||
expect(component).not.toBeNull();
|
expect(component).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should init basic component data', () => {
|
it('should init basic component data', () => {
|
||||||
component.data.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
|
component.data.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
|
||||||
component.data.httpMethod.should.be.equal('put');
|
component.data.httpMethod.should.be.equal('put');
|
||||||
component.data.path.should.be.equal('/user/{username}');
|
component.data.path.should.be.equal('/user/{username}');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should main tag', () => {
|
it('should main tag', () => {
|
||||||
component.data.methodInfo.tags.should.be.empty;
|
component.data.methodInfo.tags.should.be.empty;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,43 +14,43 @@ import {
|
||||||
import MethodsList from 'lib/components/MethodsList/methods-list';
|
import MethodsList from 'lib/components/MethodsList/methods-list';
|
||||||
import SchemaManager from 'lib/utils/SchemaManager';
|
import SchemaManager from 'lib/utils/SchemaManager';
|
||||||
|
|
||||||
|
describe('Redoc components', () => {
|
||||||
describe('ApiInfo Component', () => {
|
describe('ApiInfo Component', () => {
|
||||||
let builder;
|
let builder;
|
||||||
let component;
|
let component;
|
||||||
let fixture;
|
let fixture;
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
provide(SchemaManager, {useValue: new SchemaManager()})
|
provide(SchemaManager, {useValue: new SchemaManager()})
|
||||||
]);
|
]);
|
||||||
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||||
builder = tcb;
|
builder = tcb;
|
||||||
return schemaMgr.load('/tests/schemas/methods-list-component.json').then(() => null, (err) => { throw err; });
|
return schemaMgr.load('/tests/schemas/methods-list-component.json').then(() => null, (err) => { throw err; });
|
||||||
}));
|
}));
|
||||||
beforeEach((done) => {
|
beforeEach((done) => {
|
||||||
builder.createAsync(TestApp).then(_fixture => {
|
builder.createAsync(TestApp).then(_fixture => {
|
||||||
fixture = _fixture;
|
fixture = _fixture;
|
||||||
component = getChildDebugElement(fixture.debugElement, 'methods-list').componentInstance;
|
component = getChildDebugElement(fixture.debugElement, 'methods-list').componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
done();
|
done();
|
||||||
}, err => { throw err; });
|
}, err => { throw err; });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should init component and component data', () => {
|
it('should init component and component data', () => {
|
||||||
expect(component).not.toBeNull();
|
expect(component).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get correct tags list', () => {
|
it('should get correct tags list', () => {
|
||||||
expect(component.data.tags).not.toBeNull();
|
expect(component.data.tags).not.toBeNull();
|
||||||
component.data.tags.should.have.lengthOf(2);
|
component.data.tags.should.have.lengthOf(2);
|
||||||
component.data.tags[0].name.should.be.equal('traitTag');
|
component.data.tags[0].name.should.be.equal('traitTag');
|
||||||
component.data.tags[0].methods.should.be.empty;
|
component.data.tags[0].methods.should.be.empty;
|
||||||
component.data.tags[1].name.should.be.equal('tag1');
|
component.data.tags[1].name.should.be.equal('tag1');
|
||||||
component.data.tags[1].methods.should.have.lengthOf(2);
|
component.data.tags[1].methods.should.have.lengthOf(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/** Test component that contains an ApiInfo. */
|
/** Test component that contains an ApiInfo. */
|
||||||
@Component({selector: 'test-app'})
|
@Component({selector: 'test-app'})
|
||||||
@View({
|
@View({
|
||||||
|
|
|
@ -14,35 +14,35 @@ import {
|
||||||
import Redoc from 'lib/components/Redoc/redoc';
|
import Redoc from 'lib/components/Redoc/redoc';
|
||||||
import SchemaManager from 'lib/utils/SchemaManager';
|
import SchemaManager from 'lib/utils/SchemaManager';
|
||||||
|
|
||||||
|
describe('Redoc components', () => {
|
||||||
describe('Redoc Component', () => {
|
describe('Redoc Component', () => {
|
||||||
let builder;
|
let builder;
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
provide(SchemaManager, {useValue: new SchemaManager()})
|
provide(SchemaManager, {useValue: new SchemaManager()})
|
||||||
]);
|
]);
|
||||||
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||||
builder = tcb;
|
builder = tcb;
|
||||||
return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; });
|
return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; });
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should init component', (done) => {
|
it('should init component', (done) => {
|
||||||
builder.createAsync(TestApp).then(fixture => {
|
builder.createAsync(TestApp).then(fixture => {
|
||||||
let component = getChildDebugElement(fixture.debugElement, 'redoc').componentInstance;
|
let component = getChildDebugElement(fixture.debugElement, 'redoc').componentInstance;
|
||||||
expect(component).not.toBeNull();
|
expect(component).not.toBeNull();
|
||||||
done();
|
done();
|
||||||
}, err => done.fail(err));
|
}, err => done.fail(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should init components tree without errors', (done) => {
|
it('should init components tree without errors', (done) => {
|
||||||
builder.createAsync(TestApp).then(fixture => {
|
builder.createAsync(TestApp).then(fixture => {
|
||||||
(() => fixture.detectChanges()).should.not.throw();
|
(() => fixture.detectChanges()).should.not.throw();
|
||||||
done();
|
done();
|
||||||
}, err => done.fail(err));
|
}, err => done.fail(err));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/** Test component that contains a Redoc. */
|
/** Test component that contains a Redoc. */
|
||||||
@Component({selector: 'test-app'})
|
@Component({selector: 'test-app'})
|
||||||
@View({
|
@View({
|
||||||
|
|
|
@ -3,195 +3,197 @@
|
||||||
import SchemaManager from 'lib/utils/SchemaManager';
|
import SchemaManager from 'lib/utils/SchemaManager';
|
||||||
import {BaseComponent} from 'lib/components/base';
|
import {BaseComponent} from 'lib/components/base';
|
||||||
|
|
||||||
describe('BaseComponent', () => {
|
describe('Redoc components', () => {
|
||||||
let schemaMgr;
|
describe('BaseComponent', () => {
|
||||||
let component;
|
let schemaMgr;
|
||||||
|
let component;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
schemaMgr = new SchemaManager();
|
schemaMgr = new SchemaManager();
|
||||||
schemaMgr._schema = {tags: []};
|
schemaMgr._schema = {tags: []};
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
component = new BaseComponent(schemaMgr);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set instance properties', () => {
|
|
||||||
component.schemaMgr.should.be.equal(schemaMgr);
|
|
||||||
component.schema.should.be.of.type('object');
|
|
||||||
expect(component.componentSchema).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set componentSchema based on pointer on ngOnInit', () => {
|
|
||||||
component.pointer = '/tags';
|
|
||||||
component.ngOnInit();
|
|
||||||
component.componentSchema.should.be.equal(schemaMgr._schema.tags);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call prepareModel and init virtual methods after init', () => {
|
|
||||||
sinon.spy(component, 'prepareModel');
|
|
||||||
sinon.spy(component, 'init');
|
|
||||||
component.ngOnInit();
|
|
||||||
component.prepareModel.calledOnce.should.be.true;
|
|
||||||
component.init.calledOnce.should.be.true;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('dereference', () => {
|
|
||||||
beforeAll((done) => {
|
|
||||||
schemaMgr.load('/tests/schemas/base-component-dereference.json').then(
|
|
||||||
() => done()
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('simple dereference', () => {
|
beforeEach(() => {
|
||||||
let paramWithRef;
|
component = new BaseComponent(schemaMgr);
|
||||||
beforeAll(() => {
|
});
|
||||||
component.pointer = '/paths/test1/get';
|
|
||||||
component.ngOnInit();
|
it('should set instance properties', () => {
|
||||||
component.dereference();
|
component.schemaMgr.should.be.equal(schemaMgr);
|
||||||
paramWithRef = component.componentSchema.parameters[0];
|
component.schema.should.be.of.type('object');
|
||||||
|
expect(component.componentSchema).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set componentSchema based on pointer on ngOnInit', () => {
|
||||||
|
component.pointer = '/tags';
|
||||||
|
component.ngOnInit();
|
||||||
|
component.componentSchema.should.be.equal(schemaMgr._schema.tags);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call prepareModel and init virtual methods after init', () => {
|
||||||
|
sinon.spy(component, 'prepareModel');
|
||||||
|
sinon.spy(component, 'init');
|
||||||
|
component.ngOnInit();
|
||||||
|
component.prepareModel.calledOnce.should.be.true;
|
||||||
|
component.init.calledOnce.should.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('dereference', () => {
|
||||||
|
beforeAll((done) => {
|
||||||
|
schemaMgr.load('/tests/schemas/base-component-dereference.json').then(
|
||||||
|
() => done()
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not contain $ref property', () => {
|
describe('simple dereference', () => {
|
||||||
expect(paramWithRef.$ref).toBeUndefined();
|
let paramWithRef;
|
||||||
|
beforeAll(() => {
|
||||||
|
component.pointer = '/paths/test1/get';
|
||||||
|
component.ngOnInit();
|
||||||
|
component.dereference();
|
||||||
|
paramWithRef = component.componentSchema.parameters[0];
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not contain $ref property', () => {
|
||||||
|
expect(paramWithRef.$ref).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should inject Title if not exist based on reference', () => {
|
||||||
|
paramWithRef.title.should.be.equal('Simple');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should inject pointer', () => {
|
||||||
|
paramWithRef._pointer.should.be.equal('#/definitions/Simple');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should insert correct definition instead of reference', () => {
|
||||||
|
delete paramWithRef.title;
|
||||||
|
delete paramWithRef._pointer;
|
||||||
|
paramWithRef.should.be.deepEqual(schemaMgr.schema.definitions.Simple);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should inject Title if not exist based on reference', () => {
|
describe('nested dereference', () => {
|
||||||
paramWithRef.title.should.be.equal('Simple');
|
let paramWithRef;
|
||||||
|
beforeAll(() => {
|
||||||
|
component.pointer = '/paths/test2/get';
|
||||||
|
component.ngOnInit();
|
||||||
|
component.dereference();
|
||||||
|
paramWithRef = component.componentSchema.parameters[0];
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not touch title if exist', () => {
|
||||||
|
paramWithRef.title.should.be.equal('NesteTitle');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resolve nested schema', () => {
|
||||||
|
expect(paramWithRef.properties.subschema.$ref).toBeUndefined();
|
||||||
|
paramWithRef._pointer.should.be.equal('#/definitions/Nested');
|
||||||
|
paramWithRef.properties.subschema._pointer.should.be.equal('#/definitions/Simple');
|
||||||
|
paramWithRef.properties.subschema.type.should.be.equal('object');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should inject pointer', () => {
|
describe('array schema dereference', () => {
|
||||||
paramWithRef._pointer.should.be.equal('#/definitions/Simple');
|
let paramWithRef;
|
||||||
});
|
beforeAll(() => {
|
||||||
|
component.pointer = '/paths/test3/get';
|
||||||
|
component.ngOnInit();
|
||||||
|
component.dereference();
|
||||||
|
paramWithRef = component.componentSchema.parameters[0];
|
||||||
|
});
|
||||||
|
|
||||||
it('should insert correct definition instead of reference', () => {
|
it('should resolve array schema', () => {
|
||||||
delete paramWithRef.title;
|
expect(paramWithRef.$ref).toBeUndefined();
|
||||||
delete paramWithRef._pointer;
|
expect(paramWithRef.items.schema.$ref).toBeUndefined();
|
||||||
paramWithRef.should.be.deepEqual(schemaMgr.schema.definitions.Simple);
|
paramWithRef.type.should.be.equal('array');
|
||||||
|
paramWithRef._pointer.should.be.equal('#/definitions/ArrayOfSimple');
|
||||||
|
paramWithRef.items.schema._pointer.should.be.equal('#/definitions/Simple');
|
||||||
|
paramWithRef.items.schema.type.should.be.equal('object');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('nested dereference', () => {
|
describe('mergeAllOf', () => {
|
||||||
let paramWithRef;
|
beforeAll((done) => {
|
||||||
beforeAll(() => {
|
schemaMgr.load('tests/schemas/base-component-joinallof.json').then(() => done());
|
||||||
component.pointer = '/paths/test2/get';
|
|
||||||
component.ngOnInit();
|
|
||||||
component.dereference();
|
|
||||||
paramWithRef = component.componentSchema.parameters[0];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not touch title if exist', () => {
|
describe('Simple allOf merge', () => {
|
||||||
paramWithRef.title.should.be.equal('NesteTitle');
|
let joined;
|
||||||
|
beforeAll(() => {
|
||||||
|
component.pointer = '/definitions/SimpleAllOf';
|
||||||
|
component.ngOnInit();
|
||||||
|
component.dereference();
|
||||||
|
component.joinAllOf();
|
||||||
|
joined = component.componentSchema;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove $allOf field', () => {
|
||||||
|
expect(joined.allOf).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set type object', () => {
|
||||||
|
joined.type.should.be.equal('object');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should merge properties', () => {
|
||||||
|
Object.keys(joined.properties).length.should.be.equal(3);
|
||||||
|
Object.keys(joined.properties).should.be.deepEqual(['prop1', 'prop2', 'prop3']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should merge required', () => {
|
||||||
|
joined.required.length.should.be.equal(2);
|
||||||
|
joined.required.should.be.deepEqual(['prop1', 'prop3']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should resolve nested schema', () => {
|
describe('AllOf with refrence', () => {
|
||||||
expect(paramWithRef.properties.subschema.$ref).toBeUndefined();
|
let joined;
|
||||||
paramWithRef._pointer.should.be.equal('#/definitions/Nested');
|
beforeAll(() => {
|
||||||
paramWithRef.properties.subschema._pointer.should.be.equal('#/definitions/Simple');
|
component.pointer = '/definitions/AllOfWithRef';
|
||||||
paramWithRef.properties.subschema.type.should.be.equal('object');
|
component.ngOnInit();
|
||||||
});
|
component.dereference();
|
||||||
});
|
component.joinAllOf();
|
||||||
|
joined = component.componentSchema;
|
||||||
|
});
|
||||||
|
|
||||||
describe('array schema dereference', () => {
|
it('should remove $allOf field', () => {
|
||||||
let paramWithRef;
|
expect(joined.allOf).toBeNull();
|
||||||
beforeAll(() => {
|
});
|
||||||
component.pointer = '/paths/test3/get';
|
|
||||||
component.ngOnInit();
|
it('should set type object', () => {
|
||||||
component.dereference();
|
joined.type.should.be.equal('object');
|
||||||
paramWithRef = component.componentSchema.parameters[0];
|
});
|
||||||
|
|
||||||
|
it('should merge properties', () => {
|
||||||
|
Object.keys(joined.properties).length.should.be.equal(2);
|
||||||
|
Object.keys(joined.properties).should.be.deepEqual(['id', 'prop3']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should merge required', () => {
|
||||||
|
joined.required.length.should.be.equal(2);
|
||||||
|
joined.required.should.be.deepEqual(['id', 'prop3']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should resolve array schema', () => {
|
describe('Incorrect or not supported allOf', () => {
|
||||||
expect(paramWithRef.$ref).toBeUndefined();
|
it('should throw when properties or required is set on the same level as allOf', () => {
|
||||||
expect(paramWithRef.items.schema.$ref).toBeUndefined();
|
component.pointer = '/definitions/BadAllOf2';
|
||||||
paramWithRef.type.should.be.equal('array');
|
component.ngOnInit();
|
||||||
paramWithRef._pointer.should.be.equal('#/definitions/ArrayOfSimple');
|
component.dereference();
|
||||||
paramWithRef.items.schema._pointer.should.be.equal('#/definitions/Simple');
|
(() => component.joinAllOf()).should.throw();
|
||||||
paramWithRef.items.schema.type.should.be.equal('object');
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('mergeAllOf', () => {
|
it('should throw when merging non-object schemas', () => {
|
||||||
beforeAll((done) => {
|
component.pointer = '/definitions/BadAllOf1';
|
||||||
schemaMgr.load('tests/schemas/base-component-joinallof.json').then(() => done());
|
component.ngOnInit();
|
||||||
});
|
component.dereference();
|
||||||
|
(() => component.joinAllOf()).should.throw();
|
||||||
describe('Simple allOf merge', () => {
|
});
|
||||||
let joined;
|
|
||||||
beforeAll(() => {
|
|
||||||
component.pointer = '/definitions/SimpleAllOf';
|
|
||||||
component.ngOnInit();
|
|
||||||
component.dereference();
|
|
||||||
component.joinAllOf();
|
|
||||||
joined = component.componentSchema;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove $allOf field', () => {
|
xdescribe('Merge array allOf', () => {
|
||||||
expect(joined.allOf).toBeNull();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set type object', () => {
|
|
||||||
joined.type.should.be.equal('object');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should merge properties', () => {
|
|
||||||
Object.keys(joined.properties).length.should.be.equal(3);
|
|
||||||
Object.keys(joined.properties).should.be.deepEqual(['prop1', 'prop2', 'prop3']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should merge required', () => {
|
|
||||||
joined.required.length.should.be.equal(2);
|
|
||||||
joined.required.should.be.deepEqual(['prop1', 'prop3']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('AllOf with refrence', () => {
|
|
||||||
let joined;
|
|
||||||
beforeAll(() => {
|
|
||||||
component.pointer = '/definitions/AllOfWithRef';
|
|
||||||
component.ngOnInit();
|
|
||||||
component.dereference();
|
|
||||||
component.joinAllOf();
|
|
||||||
joined = component.componentSchema;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should remove $allOf field', () => {
|
|
||||||
expect(joined.allOf).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set type object', () => {
|
|
||||||
joined.type.should.be.equal('object');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should merge properties', () => {
|
|
||||||
Object.keys(joined.properties).length.should.be.equal(2);
|
|
||||||
Object.keys(joined.properties).should.be.deepEqual(['id', 'prop3']);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should merge required', () => {
|
|
||||||
joined.required.length.should.be.equal(2);
|
|
||||||
joined.required.should.be.deepEqual(['id', 'prop3']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Incorrect or not supported allOf', () => {
|
|
||||||
it('should throw when properties or required is set on the same level as allOf', () => {
|
|
||||||
component.pointer = '/definitions/BadAllOf2';
|
|
||||||
component.ngOnInit();
|
|
||||||
component.dereference();
|
|
||||||
(() => component.joinAllOf()).should.throw();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw when merging non-object schemas', () => {
|
|
||||||
component.pointer = '/definitions/BadAllOf1';
|
|
||||||
component.ngOnInit();
|
|
||||||
component.dereference();
|
|
||||||
(() => component.joinAllOf()).should.throw();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
xdescribe('Merge array allOf', () => {
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,25 +2,26 @@
|
||||||
|
|
||||||
import {JsonPointer} from 'lib/utils/JsonPointer';
|
import {JsonPointer} from 'lib/utils/JsonPointer';
|
||||||
// test extended JsonPointer
|
// test extended JsonPointer
|
||||||
|
describe('Utils', () => {
|
||||||
|
describe('JsonPointer', () => {
|
||||||
|
it('should return correct base name', ()=> {
|
||||||
|
JsonPointer.baseName('/level1/level2/name').should.be.equal('name');
|
||||||
|
JsonPointer.baseName('/level1/level2/name', 2).should.be.equal('level2');
|
||||||
|
JsonPointer.baseName('/level1/level2/name', 3).should.be.equal('level1');
|
||||||
|
});
|
||||||
|
|
||||||
describe('JsonPointer', () => {
|
it('should return correct dir name', ()=> {
|
||||||
it('should return correct base name', ()=> {
|
JsonPointer.dirName('/level1/level2/name').should.be.equal('/level1/level2');
|
||||||
JsonPointer.baseName('/level1/level2/name').should.be.equal('name');
|
JsonPointer.dirName('/level1/level2/name', 2).should.be.equal('/level1');
|
||||||
JsonPointer.baseName('/level1/level2/name', 2).should.be.equal('level2');
|
JsonPointer.dirName('/level1/level2/name', 3).should.be.equal('');
|
||||||
JsonPointer.baseName('/level1/level2/name', 3).should.be.equal('level1');
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should return correct dir name', ()=> {
|
it('should handle relative pointers (starting with #) without errors', ()=> {
|
||||||
JsonPointer.dirName('/level1/level2/name').should.be.equal('/level1/level2');
|
JsonPointer.parse('#/level1/level2/name').should.be.deepEqual(['level1', 'level2', 'name']);
|
||||||
JsonPointer.dirName('/level1/level2/name', 2).should.be.equal('/level1');
|
});
|
||||||
JsonPointer.dirName('/level1/level2/name', 3).should.be.equal('');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle relative pointers (starting with #) without errors', ()=> {
|
it('should join correctly', ()=> {
|
||||||
JsonPointer.parse('#/level1/level2/name').should.be.deepEqual(['level1', 'level2', 'name']);
|
JsonPointer.join('#/level1', ['level2', 'name']).should.be.equal('/level1/level2/name');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should join correctly', ()=> {
|
|
||||||
JsonPointer.join('#/level1', ['level2', 'name']).should.be.equal('/level1/level2/name');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,44 +1,36 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import SchemaManager from 'lib/utils/SchemaManager';
|
import SchemaManager from 'lib/utils/SchemaManager';
|
||||||
describe('Schema manager', () => {
|
describe('Utils', () => {
|
||||||
let schemaMgr;
|
describe('Schema manager', () => {
|
||||||
|
let schemaMgr;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
schemaMgr = new SchemaManager();
|
schemaMgr = new SchemaManager();
|
||||||
});
|
|
||||||
|
|
||||||
it('Should initialize with empty schema', ()=> {
|
|
||||||
schemaMgr.schema.should.be.empty;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should be a singleton', ()=> {
|
|
||||||
(new SchemaManager()).should.be.equal(schemaMgr);
|
|
||||||
SchemaManager.instance().should.be.equal(schemaMgr);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('load should return a promise', ()=> {
|
|
||||||
schemaMgr.load('/tests/schemas/extended-petstore.json').should.be.instanceof(Promise);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('load should reject promise for invalid url', (done)=> {
|
|
||||||
schemaMgr.load('/nonexisting/schema.json').then(() => {
|
|
||||||
throw new Error('Succees handler should not be called');
|
|
||||||
}, () => {
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('load should resolve promise for valid url', (done)=> {
|
it('Should initialize with empty schema', ()=> {
|
||||||
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
|
schemaMgr.schema.should.be.empty;
|
||||||
done();
|
|
||||||
}, () => {
|
|
||||||
throw new Error('Error handler should not be called');
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('Schema manager basic functionality', ()=> {
|
it('Should be a singleton', ()=> {
|
||||||
beforeAll(function (done) {
|
(new SchemaManager()).should.be.equal(schemaMgr);
|
||||||
|
SchemaManager.instance().should.be.equal(schemaMgr);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('load should return a promise', ()=> {
|
||||||
|
schemaMgr.load('/tests/schemas/extended-petstore.json').should.be.instanceof(Promise);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('load should reject promise for invalid url', (done)=> {
|
||||||
|
schemaMgr.load('/nonexisting/schema.json').then(() => {
|
||||||
|
throw new Error('Succees handler should not be called');
|
||||||
|
}, () => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('load should resolve promise for valid url', (done)=> {
|
||||||
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
|
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
|
||||||
done();
|
done();
|
||||||
}, () => {
|
}, () => {
|
||||||
|
@ -46,182 +38,192 @@ describe('Schema manager', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Schema manager basic functionality', ()=> {
|
||||||
it('should contain non-empty schema', ()=> {
|
beforeAll(function (done) {
|
||||||
schemaMgr.schema.should.be.an.Object();
|
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
|
||||||
schemaMgr.schema.should.be.not.empty;
|
done();
|
||||||
});
|
}, () => {
|
||||||
|
throw new Error('Error handler should not be called');
|
||||||
it('should correctly init api url', ()=> {
|
});
|
||||||
schemaMgr.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('byPointer method', () => {
|
|
||||||
it('should return correct schema part', ()=> {
|
|
||||||
let part = schemaMgr.byPointer('/tags/3');
|
|
||||||
part.should.be.deepEqual(schemaMgr.schema.tags[3]);
|
|
||||||
part.should.be.equal(schemaMgr.schema.tags[3]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null for incorrect pointer', ()=> {
|
|
||||||
let part = schemaMgr.byPointer('/incorrect/pointer');
|
it('should contain non-empty schema', ()=> {
|
||||||
expect(part).toBeNull();
|
schemaMgr.schema.should.be.an.Object();
|
||||||
|
schemaMgr.schema.should.be.not.empty;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should correctly init api url', ()=> {
|
||||||
|
schemaMgr.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('byPointer method', () => {
|
||||||
|
it('should return correct schema part', ()=> {
|
||||||
|
let part = schemaMgr.byPointer('/tags/3');
|
||||||
|
part.should.be.deepEqual(schemaMgr.schema.tags[3]);
|
||||||
|
part.should.be.equal(schemaMgr.schema.tags[3]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return null for incorrect pointer', ()=> {
|
||||||
|
let part = schemaMgr.byPointer('/incorrect/pointer');
|
||||||
|
expect(part).toBeNull();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('getTagsMap method', () => {
|
describe('getTagsMap method', () => {
|
||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
schemaMgr._schema = {
|
schemaMgr._schema = {
|
||||||
|
tags: [
|
||||||
|
{name: 'tag1', description: 'info1'},
|
||||||
|
{name: 'tag2', description: 'info2', 'x-traitTag': true}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct tags map', () => {
|
||||||
|
let tagsMap = schemaMgr.getTagsMap();
|
||||||
|
let expectedResult = {
|
||||||
|
tag1: {description: 'info1', 'x-traitTag': false},
|
||||||
|
tag2: {description: 'info2', 'x-traitTag': true}
|
||||||
|
};
|
||||||
|
tagsMap.should.be.deepEqual(expectedResult);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return empty array for non-specified tags', () => {
|
||||||
|
delete schemaMgr._schema.tags;
|
||||||
|
let tagsMap = schemaMgr.getTagsMap();
|
||||||
|
tagsMap.should.be.empty;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('buildMenuTree method', () => {
|
||||||
|
let suitSchema = {
|
||||||
tags: [
|
tags: [
|
||||||
{name: 'tag1', description: 'info1'},
|
{name: 'tag1', description: 'info1', 'x-traitTag': true},
|
||||||
{name: 'tag2', description: 'info2', 'x-traitTag': true}
|
{name: 'tag2', description: 'info2'}
|
||||||
]
|
],
|
||||||
};
|
paths: {
|
||||||
});
|
test: {
|
||||||
|
put: {
|
||||||
it('should return correct tags map', () => {
|
tags: ['tag1', 'tag3'],
|
||||||
let tagsMap = schemaMgr.getTagsMap();
|
summary: 'test put'
|
||||||
let expectedResult = {
|
},
|
||||||
tag1: {description: 'info1', 'x-traitTag': false},
|
get: {
|
||||||
tag2: {description: 'info2', 'x-traitTag': true}
|
tags: ['tag1', 'tag2'],
|
||||||
};
|
summary: 'test get'
|
||||||
tagsMap.should.be.deepEqual(expectedResult);
|
},
|
||||||
});
|
// no tags
|
||||||
|
post: {
|
||||||
it('should return empty array for non-specified tags', () => {
|
summary: 'test post'
|
||||||
delete schemaMgr._schema.tags;
|
}
|
||||||
let tagsMap = schemaMgr.getTagsMap();
|
|
||||||
tagsMap.should.be.empty;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('buildMenuTree method', () => {
|
|
||||||
let suitSchema = {
|
|
||||||
tags: [
|
|
||||||
{name: 'tag1', description: 'info1', 'x-traitTag': true},
|
|
||||||
{name: 'tag2', description: 'info2'}
|
|
||||||
],
|
|
||||||
paths: {
|
|
||||||
test: {
|
|
||||||
put: {
|
|
||||||
tags: ['tag1', 'tag3'],
|
|
||||||
summary: 'test put'
|
|
||||||
},
|
|
||||||
get: {
|
|
||||||
tags: ['tag1', 'tag2'],
|
|
||||||
summary: 'test get'
|
|
||||||
},
|
|
||||||
// no tags
|
|
||||||
post: {
|
|
||||||
summary: 'test post'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let menuTree;
|
let menuTree;
|
||||||
let entries;
|
let entries;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
schemaMgr._schema = suitSchema;
|
schemaMgr._schema = suitSchema;
|
||||||
menuTree = schemaMgr.buildMenuTree();
|
menuTree = schemaMgr.buildMenuTree();
|
||||||
entries = Array.from(menuTree.entries());
|
entries = Array.from(menuTree.entries());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return instance of Map', () => {
|
it('should return instance of Map', () => {
|
||||||
menuTree.should.be.instanceof(Map);
|
menuTree.should.be.instanceof(Map);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return Map with correct number of entries', () => {
|
it('should return Map with correct number of entries', () => {
|
||||||
//2 - defined tags, 1 - tag3 and 1 [other] tag for no-tags method
|
//2 - defined tags, 1 - tag3 and 1 [other] tag for no-tags method
|
||||||
entries.length.should.be.equal(2 + 1 + 1);
|
entries.length.should.be.equal(2 + 1 + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append not defined tags to the end of list', () => {
|
it('should append not defined tags to the end of list', () => {
|
||||||
let [tag, info] = entries[2];
|
let [tag, info] = entries[2];
|
||||||
tag.should.be.equal('tag3');
|
tag.should.be.equal('tag3');
|
||||||
info.methods.length.should.be.equal(1);
|
info.methods.length.should.be.equal(1);
|
||||||
info.methods[0].summary.should.be.equal('test put');
|
info.methods[0].summary.should.be.equal('test put');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append methods without tags to [other] tag', () => {
|
it('should append methods without tags to [other] tag', () => {
|
||||||
let [tag, info] = entries[3];
|
let [tag, info] = entries[3];
|
||||||
tag.should.be.equal('[Other]');
|
tag.should.be.equal('[Other]');
|
||||||
info.methods.length.should.be.equal(1);
|
info.methods.length.should.be.equal(1);
|
||||||
info.methods[0].summary.should.be.equal('test post');
|
info.methods[0].summary.should.be.equal('test post');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should map x-traitTag to empty methods list', () => {
|
it('should map x-traitTag to empty methods list', () => {
|
||||||
let [, info] = entries[0];
|
let [, info] = entries[0];
|
||||||
info['x-traitTag'].should.be.true;
|
info['x-traitTag'].should.be.true;
|
||||||
info.methods.should.be.empty;
|
info.methods.should.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('methods for tag should contain valid pointer and summary', () => {
|
it('methods for tag should contain valid pointer and summary', () => {
|
||||||
for (let entr of entries) {
|
for (let entr of entries) {
|
||||||
let [, info] = entr;
|
let [, info] = entr;
|
||||||
info.should.be.an.Object();
|
info.should.be.an.Object();
|
||||||
info.methods.should.be.an.Array();
|
info.methods.should.be.an.Array();
|
||||||
for (let methodInfo of info.methods) {
|
for (let methodInfo of info.methods) {
|
||||||
methodInfo.should.have.keys('pointer', 'summary');
|
methodInfo.should.have.keys('pointer', 'summary');
|
||||||
let methSchema = schemaMgr.byPointer(methodInfo.pointer);
|
let methSchema = schemaMgr.byPointer(methodInfo.pointer);
|
||||||
expect(methSchema).not.toBeNull();
|
expect(methSchema).not.toBeNull();
|
||||||
if (methSchema.summary) {
|
if (methSchema.summary) {
|
||||||
methSchema.summary.should.be.equal(methodInfo.summary);
|
methSchema.summary.should.be.equal(methodInfo.summary);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getMethodParams method', () => {
|
|
||||||
beforeAll((done) => {
|
|
||||||
schemaMgr.load('/tests/schemas/schema-mgr-methodparams.json').then(() => {
|
|
||||||
done();
|
|
||||||
}, () => {
|
|
||||||
done(new Error('Error handler should not be called'));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should propagate path parameters', () => {
|
describe('getMethodParams method', () => {
|
||||||
let params = schemaMgr.getMethodParams('/paths/test1/get');
|
beforeAll((done) => {
|
||||||
params.length.should.be.equal(2);
|
schemaMgr.load('/tests/schemas/schema-mgr-methodparams.json').then(() => {
|
||||||
params[0].name.should.be.equal('methodParam');
|
done();
|
||||||
params[1].name.should.be.equal('pathParam');
|
}, () => {
|
||||||
|
done(new Error('Error handler should not be called'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should propagate path parameters', () => {
|
||||||
|
let params = schemaMgr.getMethodParams('/paths/test1/get');
|
||||||
|
params.length.should.be.equal(2);
|
||||||
|
params[0].name.should.be.equal('methodParam');
|
||||||
|
params[1].name.should.be.equal('pathParam');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should inject correct pointers', () => {
|
||||||
|
let params = schemaMgr.getMethodParams('/paths/test1/get');
|
||||||
|
params[0]._pointer.should.be.equal('/paths/test1/get/parameters/0');
|
||||||
|
params[1]._pointer.should.be.equal('/paths/test1/parameters/0');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should accept pointer directly to parameters', () => {
|
||||||
|
let params = schemaMgr.getMethodParams('/paths/test1/get/parameters', true);
|
||||||
|
expect(params).not.toBeNull();
|
||||||
|
params.length.should.be.equal(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resolve path params from Parameters Definitions Object', () => {
|
||||||
|
let params = schemaMgr.getMethodParams('/paths/test2/get', true);
|
||||||
|
params.length.should.be.equal(2);
|
||||||
|
params[0].name.should.be.equal('methodParam');
|
||||||
|
params[1].name.should.be.equal('extParam');
|
||||||
|
params[1]._pointer.should.be.equal('#/parameters/extparam');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resolve method params from Parameters Definitions Object', () => {
|
||||||
|
let params = schemaMgr.getMethodParams('/paths/test3/get', true);
|
||||||
|
params.length.should.be.equal(1);
|
||||||
|
params[0].name.should.be.equal('extParam');
|
||||||
|
params[0]._pointer.should.be.equal('#/parameters/extparam');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw for parameters other than array', () => {
|
||||||
|
let func = () => schemaMgr.getMethodParams('/paths/test4/get', true);
|
||||||
|
expect(func).toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should inject correct pointers', () => {
|
|
||||||
let params = schemaMgr.getMethodParams('/paths/test1/get');
|
|
||||||
params[0]._pointer.should.be.equal('/paths/test1/get/parameters/0');
|
|
||||||
params[1]._pointer.should.be.equal('/paths/test1/parameters/0');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should accept pointer directly to parameters', () => {
|
|
||||||
let params = schemaMgr.getMethodParams('/paths/test1/get/parameters', true);
|
|
||||||
expect(params).not.toBeNull();
|
|
||||||
params.length.should.be.equal(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should resolve path params from Parameters Definitions Object', () => {
|
|
||||||
let params = schemaMgr.getMethodParams('/paths/test2/get', true);
|
|
||||||
params.length.should.be.equal(2);
|
|
||||||
params[0].name.should.be.equal('methodParam');
|
|
||||||
params[1].name.should.be.equal('extParam');
|
|
||||||
params[1]._pointer.should.be.equal('#/parameters/extparam');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should resolve method params from Parameters Definitions Object', () => {
|
|
||||||
let params = schemaMgr.getMethodParams('/paths/test3/get', true);
|
|
||||||
params.length.should.be.equal(1);
|
|
||||||
params[0].name.should.be.equal('extParam');
|
|
||||||
params[0]._pointer.should.be.equal('#/parameters/extparam');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw for parameters other than array', () => {
|
|
||||||
let func = () => schemaMgr.getMethodParams('/paths/test4/get', true);
|
|
||||||
expect(func).toThrow();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,31 +1,33 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import {statusCodeType} from 'lib/utils/helpers';
|
import {statusCodeType} from 'lib/utils/helpers';
|
||||||
describe('statusCodeType', () => {
|
describe('Utils', () => {
|
||||||
it('Should return info for status codes within 100 and 200', ()=> {
|
describe('statusCodeType', () => {
|
||||||
statusCodeType(100).should.be.equal('info');
|
it('Should return info for status codes within 100 and 200', ()=> {
|
||||||
statusCodeType(150).should.be.equal('info');
|
statusCodeType(100).should.be.equal('info');
|
||||||
statusCodeType(199).should.be.equal('info');
|
statusCodeType(150).should.be.equal('info');
|
||||||
});
|
statusCodeType(199).should.be.equal('info');
|
||||||
|
});
|
||||||
|
|
||||||
it('Should return success for status codes within 200 and 300', ()=> {
|
it('Should return success for status codes within 200 and 300', ()=> {
|
||||||
statusCodeType(200).should.be.equal('success');
|
statusCodeType(200).should.be.equal('success');
|
||||||
statusCodeType(250).should.be.equal('success');
|
statusCodeType(250).should.be.equal('success');
|
||||||
statusCodeType(299).should.be.equal('success');
|
statusCodeType(299).should.be.equal('success');
|
||||||
});
|
});
|
||||||
it('Should return redirect for status codes within 300 and 400', ()=> {
|
it('Should return redirect for status codes within 300 and 400', ()=> {
|
||||||
statusCodeType(300).should.be.equal('redirect');
|
statusCodeType(300).should.be.equal('redirect');
|
||||||
statusCodeType(350).should.be.equal('redirect');
|
statusCodeType(350).should.be.equal('redirect');
|
||||||
statusCodeType(399).should.be.equal('redirect');
|
statusCodeType(399).should.be.equal('redirect');
|
||||||
});
|
});
|
||||||
it('Should return error for status codes above 400', ()=> {
|
it('Should return error for status codes above 400', ()=> {
|
||||||
statusCodeType(400).should.be.equal('error');
|
statusCodeType(400).should.be.equal('error');
|
||||||
statusCodeType(500).should.be.equal('error');
|
statusCodeType(500).should.be.equal('error');
|
||||||
statusCodeType(599).should.be.equal('error');
|
statusCodeType(599).should.be.equal('error');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should throw for incorrect HTTP code', ()=> {
|
it('Should throw for incorrect HTTP code', ()=> {
|
||||||
(() => statusCodeType(99)).should.throw('invalid HTTP code');
|
(() => statusCodeType(99)).should.throw('invalid HTTP code');
|
||||||
(() => statusCodeType(600)).should.throw('invalid HTTP code');
|
(() => statusCodeType(600)).should.throw('invalid HTTP code');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,105 +2,107 @@
|
||||||
|
|
||||||
import {KeysPipe, ValuesPipe, JsonPointerEscapePipe, MarkedPipe} from 'lib/utils/pipes';
|
import {KeysPipe, ValuesPipe, JsonPointerEscapePipe, MarkedPipe} from 'lib/utils/pipes';
|
||||||
|
|
||||||
describe('KeysPipe and ValuesPipe', () => {
|
describe('Pipes', () => {
|
||||||
let obj;
|
describe('KeysPipe and ValuesPipe', () => {
|
||||||
var keysPipe, valuesPipe;
|
let obj;
|
||||||
|
var keysPipe, valuesPipe;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
obj = {
|
obj = {
|
||||||
a: 1,
|
a: 1,
|
||||||
b: 2,
|
b: 2,
|
||||||
c: 3
|
c: 3
|
||||||
};
|
};
|
||||||
keysPipe = new KeysPipe();
|
keysPipe = new KeysPipe();
|
||||||
valuesPipe = new ValuesPipe();
|
valuesPipe = new ValuesPipe();
|
||||||
});
|
|
||||||
|
|
||||||
describe('KeysPipe transform', () => {
|
|
||||||
it('should return keys', () => {
|
|
||||||
var val = keysPipe.transform(obj);
|
|
||||||
val.should.be.deepEqual(['a', 'b', 'c']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not support other objects', () => {
|
describe('KeysPipe transform', () => {
|
||||||
(() => keysPipe.transform(45)).should.throw();
|
it('should return keys', () => {
|
||||||
(() => keysPipe.transform('45')).should.throw();
|
var val = keysPipe.transform(obj);
|
||||||
|
val.should.be.deepEqual(['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not support other objects', () => {
|
||||||
|
(() => keysPipe.transform(45)).should.throw();
|
||||||
|
(() => keysPipe.transform('45')).should.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not throw on blank input', () => {
|
||||||
|
(() => valuesPipe.transform()).should.not.throw();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw on blank input', () => {
|
describe('KeysPipe transform', () => {
|
||||||
(() => valuesPipe.transform()).should.not.throw();
|
it('should return values', () => {
|
||||||
|
var val = valuesPipe.transform(obj);
|
||||||
|
val.should.be.deepEqual([1, 2, 3]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not support other objects', () => {
|
||||||
|
(() => valuesPipe.transform(45)).should.throw();
|
||||||
|
(() => valuesPipe.transform('45')).should.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not throw on blank input', () => {
|
||||||
|
(() => keysPipe.transform()).should.not.throw();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('KeysPipe transform', () => {
|
describe('JsonPointerEscapePipe', () => {
|
||||||
it('should return values', () => {
|
let unescaped;
|
||||||
var val = valuesPipe.transform(obj);
|
let escaped;
|
||||||
val.should.be.deepEqual([1, 2, 3]);
|
var pipe;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
unescaped = 'test/path~1';
|
||||||
|
escaped = 'test~1path~01';
|
||||||
|
pipe = new JsonPointerEscapePipe();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not support other objects', () => {
|
describe('JsonPointerEscapePipe transform', () => {
|
||||||
(() => valuesPipe.transform(45)).should.throw();
|
it('should escpae pointer', () => {
|
||||||
(() => valuesPipe.transform('45')).should.throw();
|
var val = pipe.transform(unescaped);
|
||||||
|
val.should.be.equal(escaped);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not support other objects', () => {
|
||||||
|
(() => pipe.transform(45)).should.throw();
|
||||||
|
(() => pipe.transform({})).should.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not throw on blank input', () => {
|
||||||
|
(() => pipe.transform()).should.not.throw();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('MarkedPipe', () => {
|
||||||
|
let unmarked;
|
||||||
|
let marked;
|
||||||
|
var pipe;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
unmarked = 'test\n';
|
||||||
|
marked = '<p>test</p>\n';
|
||||||
|
pipe = new MarkedPipe();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not throw on blank input', () => {
|
describe('MarkedPipe transform', () => {
|
||||||
(() => keysPipe.transform()).should.not.throw();
|
it('should escpae pointer', () => {
|
||||||
});
|
var val = pipe.transform(unmarked);
|
||||||
});
|
val.should.be.equal(marked);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('JsonPointerEscapePipe', () => {
|
it('should not support other objects', () => {
|
||||||
let unescaped;
|
(() => pipe.transform(45)).should.throw();
|
||||||
let escaped;
|
(() => pipe.transform({})).should.throw();
|
||||||
var pipe;
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
it('should not throw on blank input', () => {
|
||||||
unescaped = 'test/path~1';
|
(() => pipe.transform()).should.not.throw();
|
||||||
escaped = 'test~1path~01';
|
});
|
||||||
pipe = new JsonPointerEscapePipe();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('JsonPointerEscapePipe transform', () => {
|
|
||||||
it('should escpae pointer', () => {
|
|
||||||
var val = pipe.transform(unescaped);
|
|
||||||
val.should.be.equal(escaped);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not support other objects', () => {
|
|
||||||
(() => pipe.transform(45)).should.throw();
|
|
||||||
(() => pipe.transform({})).should.throw();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not throw on blank input', () => {
|
|
||||||
(() => pipe.transform()).should.not.throw();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('MarkedPipe', () => {
|
|
||||||
let unmarked;
|
|
||||||
let marked;
|
|
||||||
var pipe;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
unmarked = 'test\n';
|
|
||||||
marked = '<p>test</p>\n';
|
|
||||||
pipe = new MarkedPipe();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('MarkedPipe transform', () => {
|
|
||||||
it('should escpae pointer', () => {
|
|
||||||
var val = pipe.transform(unmarked);
|
|
||||||
val.should.be.equal(marked);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not support other objects', () => {
|
|
||||||
(() => pipe.transform(45)).should.throw();
|
|
||||||
(() => pipe.transform({})).should.throw();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not throw on blank input', () => {
|
|
||||||
(() => pipe.transform()).should.not.throw();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user