| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import {expect} from 'chai';
- import {format} from '@e22m4u/js-format';
- import {ProjectionSchemaRegistry} from './projection-schema-registry.js';
- const SCHEMA = {foo: true, bar: false};
- const SCHEMA_NAME = 'mySchema';
- const SCHEMA_DEF = {name: SCHEMA_NAME, schema: SCHEMA};
- describe('ProjectionSchemaRegistry', function () {
- describe('defineSchema', function () {
- it('should add the given definition to registry', function () {
- const S = new ProjectionSchemaRegistry();
- S.defineSchema(SCHEMA_DEF);
- const res = S.getDefinition(SCHEMA_NAME);
- expect(res).to.be.eq(SCHEMA_DEF);
- });
- it('should throw an error if the given name is already registered', function () {
- const S = new ProjectionSchemaRegistry();
- S.defineSchema(SCHEMA_DEF);
- const throwable = () => S.defineSchema(SCHEMA_DEF);
- const error = format(
- 'Projection schema %v is already registered.',
- SCHEMA_NAME,
- );
- expect(throwable).to.throw(error);
- });
- });
- describe('hasSchema', function () {
- it('should return true if the given name is registered', function () {
- const S = new ProjectionSchemaRegistry();
- const res1 = S.hasSchema(SCHEMA_NAME);
- expect(res1).to.be.false;
- S.defineSchema(SCHEMA_DEF);
- const res2 = S.hasSchema(SCHEMA_NAME);
- expect(res2).to.be.true;
- });
- });
- describe('getSchema', function () {
- it('should throw an error if the given name is not registered', function () {
- const S = new ProjectionSchemaRegistry();
- const throwable = () => S.getSchema(SCHEMA_NAME);
- const error = format('Projection schema %v is not found.', SCHEMA_NAME);
- expect(throwable).to.throw(error);
- });
- it('should return registered schema', function () {
- const S = new ProjectionSchemaRegistry();
- S.defineSchema(SCHEMA_DEF);
- const res = S.getSchema(SCHEMA_NAME);
- expect(res).to.be.eq(SCHEMA);
- });
- });
- describe('getDefinition', function () {
- it('should throw an error if the given name is not registered', function () {
- const S = new ProjectionSchemaRegistry();
- const throwable = () => S.getDefinition(SCHEMA_NAME);
- const error = format(
- 'Projection definition %v is not found.',
- SCHEMA_NAME,
- );
- expect(throwable).to.throw(error);
- });
- it('should return registered schema', function () {
- const S = new ProjectionSchemaRegistry();
- S.defineSchema(SCHEMA_DEF);
- const res = S.getDefinition(SCHEMA_NAME);
- expect(res).to.be.eq(SCHEMA_DEF);
- });
- });
- });
|