|
@@ -1,18 +1,9 @@
|
|
|
import {expect} from 'chai';
|
|
import {expect} from 'chai';
|
|
|
|
|
+import {DataType} from './data-type.js';
|
|
|
import {DataSchemaRegistry} from './data-schema-registry.js';
|
|
import {DataSchemaRegistry} from './data-schema-registry.js';
|
|
|
|
|
|
|
|
describe('DataSchemaRegistry', function () {
|
|
describe('DataSchemaRegistry', function () {
|
|
|
describe('defineSchema', function () {
|
|
describe('defineSchema', function () {
|
|
|
- it('should throw an error if the schema name is already registered', function () {
|
|
|
|
|
- const S = new DataSchemaRegistry();
|
|
|
|
|
- const schemaDef = {name: 'mySchema', schema: {}};
|
|
|
|
|
- S.defineSchema(schemaDef);
|
|
|
|
|
- const throwable = () => S.defineSchema(schemaDef);
|
|
|
|
|
- expect(throwable).to.throw(
|
|
|
|
|
- 'Data schema "mySchema" is already registered.',
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
it('should register the given definition', function () {
|
|
it('should register the given definition', function () {
|
|
|
const S = new DataSchemaRegistry();
|
|
const S = new DataSchemaRegistry();
|
|
|
const schemaDef = {name: 'mySchema', schema: {}};
|
|
const schemaDef = {name: 'mySchema', schema: {}};
|
|
@@ -21,6 +12,18 @@ describe('DataSchemaRegistry', function () {
|
|
|
expect(res).to.be.eql(schemaDef);
|
|
expect(res).to.be.eql(schemaDef);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ it('should override a registered definition', function () {
|
|
|
|
|
+ const S = new DataSchemaRegistry();
|
|
|
|
|
+ const def1 = {name: 'mySchema', schema: {type: DataType.STRING}};
|
|
|
|
|
+ const def2 = {name: 'mySchema', schema: {type: DataType.NUMBER}};
|
|
|
|
|
+ S.defineSchema(def1);
|
|
|
|
|
+ const res1 = S.getDefinition(def1.name);
|
|
|
|
|
+ expect(res1).to.be.eql(def1);
|
|
|
|
|
+ S.defineSchema(def2);
|
|
|
|
|
+ const res2 = S.getDefinition(def2.name);
|
|
|
|
|
+ expect(res2).to.be.eql(def2);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
it('should return the current instance', function () {
|
|
it('should return the current instance', function () {
|
|
|
const S = new DataSchemaRegistry();
|
|
const S = new DataSchemaRegistry();
|
|
|
const res = S.defineSchema({name: 'mySchema', schema: {}});
|
|
const res = S.defineSchema({name: 'mySchema', schema: {}});
|