Add BaseComponent joinAllOf test suite

This commit is contained in:
Roman Hotsiy 2015-12-14 10:18:46 +02:00
parent 54461e3582
commit 5b32d31d13
2 changed files with 173 additions and 0 deletions

View File

@ -109,4 +109,87 @@ describe('BaseComponent', () => {
});
});
});
describe('mergeAllOf', () => {
before(() => {
return schemaMgr.load('tests/schemas/base-component-joinallof.json');
});
describe('Simple allOf merge', () => {
let joined;
before(() => {
component.pointer = '/definitions/SimpleAllOf';
component.onInit();
component.dereference();
component.joinAllOf();
joined = component.componentSchema;
});
it('should remove $allOf field', () => {
expect(joined.allOf).to.not.exist;
});
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.deep.equal(['prop1', 'prop2', 'prop3']);
});
it('should merge required', () => {
joined.required.length.should.be.equal(2);
joined.required.should.be.deep.equal(['prop1', 'prop3']);
});
});
describe('AllOf with refrence', () => {
let joined;
before(() => {
component.pointer = '/definitions/AllOfWithRef';
component.onInit();
component.dereference();
component.joinAllOf();
joined = component.componentSchema;
});
it('should remove $allOf field', () => {
expect(joined.allOf).to.not.exist;
});
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.deep.equal(['id', 'prop3']);
});
it('should merge required', () => {
joined.required.length.should.be.equal(2);
joined.required.should.be.deep.equal(['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.onInit();
component.dereference();
component.joinAllOf.bind(component).should.throw();
});
it('should throw when merging non-object schemas', () => {
component.pointer = '/definitions/BadAllOf1';
component.onInit();
component.dereference();
component.joinAllOf.bind(component).should.throw();
});
});
describe.skip('Merge array allOf', () => {
});
});
});

View File

@ -0,0 +1,90 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test schema"
},
"host": "petstore.swagger.io",
"basePath": "/v2/",
"definitions": {
"Simple": {
"type": "object",
"required": ["id"],
"properties": {
"id": {
"type": "integer"
}
}
},
"SimpleAllOf": {
"allOf": [
{
"type": "object",
"required": ["prop1"],
"properties": {
"prop1": {
"type": "string"
},
"prop2": {
"type": "string"
}
}
},
{
"type": "object",
"required": ["prop3"],
"properties": {
"prop3": {
"type": "string"
}
}
}
]
},
"AllOfWithRef": {
"allOf": [
{
"$ref": "#/definitions/Simple"
},
{
"type": "object",
"required": ["prop3"],
"properties": {
"prop3": {
"type": "string"
}
}
}
]
},
"BadAllOf1": {
"allOf": [
{
"$ref": "#/definitions/Simple"
},
{
"type": "string",
}
]
},
"BadAllOf2": {
"properties": {},
"allOf": [
{
"$ref": "#/definitions/Simple"
},
{
"type": "object",
"required": ["prop3"],
"properties": {
"prop3": {
"type": "string"
}
}
}
]
}
},
"paths": {
}
}