UNPKG

@buggyorg/library-specification

Version:

Specification for buggy component library servers.

160 lines (138 loc) 7.86 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = function (setup) { _chai2.default.use(_chaiHttp2.default); _chai2.default.use(_chaiAsPromised2.default); var expect = _chai2.default.expect; describe('Meta information', function () { it('gets meta information for a component', function () { return setup({ components: [{ componentId: 'a', version: '1.0.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: { a: { x: [{ value: 'y', version: '1.0.0' }] } } }).then(function (app) { return _chai2.default.request(app).get('/meta/a/x'); }).then(function (res) { expect(res.status).to.equal(200); expect(res.body).to.equal('y'); }); }); it('uses latest meta information', function () { return setup({ components: [{ componentId: 'a', version: '1.0.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }, { componentId: 'a', version: '0.8.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: { a: { x: [{ value: 'y', version: '0.8.0' }, { value: 'z', version: '1.0.0' }] } } }).then(function (app) { return _chai2.default.request(app).get('/meta/a/x'); }).then(function (res) { expect(res.status).to.equal(200); expect(res.body).to.equal('z'); }); }); it('uses meta information from older components', function () { return setup({ components: [{ componentId: 'a', version: '1.0.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }, { componentId: 'a', version: '0.8.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: { a: { x: [{ value: 'y', version: '0.8.0' }] } } }).then(function (app) { return _chai2.default.request(app).get('/meta/a/x'); }).then(function (res) { expect(res.status).to.equal(200); expect(res.body).to.equal('y'); }); }); it('allows specific queries with version information', function () { return setup({ components: [{ componentId: 'a', version: '1.0.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }, { componentId: 'a', version: '0.8.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: { a: { x: [{ value: 'y', version: '0.8.0' }, { value: 'z', version: '1.0.0' }] } } }).then(function (app) { return _chai2.default.request(app).get('/meta/a/version/0.8.0/x'); }).then(function (res) { expect(res.status).to.equal(200); expect(res.body).to.equal('y'); }); }); it('can query all meta keys for a component', function () { return setup({ components: [{ componentId: 'a', version: '0.1.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: { a: { x: [{ value: 'y', version: '0.1.0' }], y: [{ value: 'z', version: '0.1.0' }] } } }).then(function (app) { return _chai2.default.request(app).get('/meta/a'); }).then(function (res) { expect(res.status).to.equal(200); expect(res.body).to.have.members(['x', 'y']); }); }); it('queries all meta keys for a component at a specific version', function () { return setup({ components: [{ componentId: 'a', version: '1.0.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }, { componentId: 'a', version: '0.8.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: { a: { x: [{ value: 'y', version: '0.8.0' }], y: [{ value: 'z', version: '1.0.0' }] } } }).then(function (app) { return _chai2.default.request(app).get('/meta/a/version/0.8.0'); }).then(function (res) { expect(res.status).to.equal(200); expect(res.body).to.eql(['x']); }); }); it('queries all meta keys for a component at a specific version and earlier', function () { return setup({ components: [{ componentId: 'a', version: '1.0.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }, { componentId: 'a', version: '0.8.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: { a: { x: [{ value: 'y', version: '0.8.0' }], y: [{ value: 'z', version: '1.0.0' }] } } }).then(function (app) { return _chai2.default.request(app).get('/meta/a/version/1.0.0'); }).then(function (res) { expect(res.status).to.equal(200); expect(res.body).to.have.members(['x', 'y']); }); }); it('sets meta information for a component', function () { return setup({ components: [{ componentId: 'a', version: '0.1.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: {} }).then(function (app) { return _chai2.default.request(app).post('/meta/a/x').send({ value: 'z' }).then(function (res) { return expect(res.status).to.equal(204); }).then(function () { return _chai2.default.request(app).get('/meta/a/x'); }).then(function (res) { expect(res.status).to.equal(200); expect(res.body).to.equal('z'); }); }); }); it('sets meta information for the latest version of the component', function () { return setup({ components: [{ componentId: 'a', version: '0.1.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }, { componentId: 'a', version: '0.2.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: {} }).then(function (app) { return _chai2.default.request(app).post('/meta/a/x').send({ value: 'z' }).then(function (res) { return expect(res.status).to.equal(204); }).then(function () { return _chai2.default.request(app).get('/meta/a/version/0.1.0'); }).then(function (res) { expect(res.status).to.equal(200); expect(res.body).to.have.length(0); }); }); }); it('fails to get non-existing meta information', function () { return setup({ components: [{ componentId: 'a', version: '0.1.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: { a: { x: [{ value: 'y', version: '0.1.0' }] } } }).then(function (app) { expect(_chai2.default.request(app).get('/meta/a/z').then(function (res) {})).to.be.rejected; }); }); it('fails to get meta information for a non-existing component', function () { return setup({ components: [{ componentId: 'a', version: '0.1.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: { a: { x: [{ value: 'y', version: '0.1.0' }] } } }).then(function (app) { expect(_chai2.default.request(app).get('/meta/b/x').then(function (res) {})).to.be.rejected; }); }); it('fails to set meta information for a non-existing component', function () { return setup({ components: [], meta: {} }).then(function (app) { return expect(_chai2.default.request(app).post('/meta/b/x').send({ value: 'z' }).then(function (res) {})).to.be.rejected; }); }); it('errors if the post value is invalid', function () { return setup({ components: [{ componentId: 'a', version: '0.1.0', ports: [{ port: 'in', kind: 'input', type: 'generic' }] }], meta: { a: { x: [{ value: 'y', version: '0.1.0' }] } } }).then(function (app) { return expect(_chai2.default.request(app).post('/meta/a/x').send({ X: 4 }).then(function (res) { expect(res.status).to.equal(400); })).to.be.rejected; }); }); }); }; var _chai = require('chai'); var _chai2 = _interopRequireDefault(_chai); var _chaiHttp = require('chai-http'); var _chaiHttp2 = _interopRequireDefault(_chaiHttp); var _chaiAsPromised = require('chai-as-promised'); var _chaiAsPromised2 = _interopRequireDefault(_chaiAsPromised); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }