@buggyorg/library-specification
Version:
Specification for buggy component library servers.
119 lines (103 loc) • 5.63 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (setup) {
_chai2.default.use(_chaiHttp2.default);
var expect = _chai2.default.expect;
describe('Components', function () {
it('gets the number of components', function () {
return setup({ components: [] }).then(function (app) {
return _chai2.default.request(app).get('/components/count');
}).then(function (res) {
expect(res.body).to.equal(0);
}).then(function () {
return setup({ components: [{ componentId: 'a', value: 1, ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '0.1.0' }, { componentId: 'b', value: 2, ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '1.0.0' }] });
}).then(function (app) {
return _chai2.default.request(app).get('/components');
}).then(function (res) {
expect(res.body).to.have.members(['a', 'b']);
});
});
it('can query a specific component', function () {
return setup({ components: [{ componentId: 'a', value: 1, ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '0.1.0' }, { componentId: 'b', value: 2, ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '1.0.0' }] }).then(function (app) {
return _chai2.default.request(app).get('/components/get/a');
}).then(function (res) {
expect(res.body.value).to.equal(1);
});
});
it('can query a specific component with a given version', function () {
return setup({ components: [{ componentId: 'a', value: 1, ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '0.1.0' }, { componentId: 'a', value: 2, ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '0.2.0' }] }).then(function (app) {
return _chai2.default.request(app).get('/components/get/a/version/0.2.0');
}).then(function (res) {
expect(res.body.value).to.equal(2);
});
});
it('sends an error code if the specific component with a given version does not exist', function () {
return setup({ components: [{ componentId: 'a', value: 1, ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '0.1.0' }, { componentId: 'a', value: 2, ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '0.2.0' }] }).then(function (app) {
return _chai2.default.request(app).get('/components/get/a/version/0.1.2');
}).then(function (res) {
expect(false).to.be.true;
}).catch(function (err) {
expect(err.status).to.equal(404);
});
});
it('sends an error code if the component does not exist', function () {
return setup({ components: [] }).then(function (app) {
return _chai2.default.request(app).get('/components/get/b');
}).then(function (res) {
expect(false).to.be.true;
}).catch(function (err) {
expect(err.status).to.equal(404);
});
});
it('inserts new components', function () {
return setup({ components: [] }).then(function (app) {
return _chai2.default.request(app).post('/components').send({ componentId: 'a', ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '1.0.0' }).then(function (res) {
expect(res.status).to.equal(204);
}).then(function () {
return _chai2.default.request(app).get('/components/count');
}).then(function (res) {
return expect(res.body).to.equal(1);
});
});
});
it('inserting an invalid component gives a 400 status code', function () {
return setup({ components: [] }).then(function (app) {
return _chai2.default.request(app).post('/components').send({ componentId: 'a' }) // no ports, no version
.then(function (res) {
expect.fail('Adding an invalid component should send a 400 status code.');
}).catch(function (err) {
expect(err.status).to.equal(400);
});
});
});
it('it is impossible to add two components with the same name', function () {
return setup({ components: [] }).then(function (app) {
return _chai2.default.request(app).post('/components').send({ componentId: 'a', ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '1.0.0' }).then(function (res) {
return _chai2.default.request(app).post('/components').send({ componentId: 'a', ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '1.0.0' });
}).then(function (res) {
expect.fail('Adding a component twice should be impossible.');
}).catch(function (err) {
expect(err.status).to.equal(409);
});
});
});
it('updates a component', function () {
setup({ components: [{ componentId: 'b' }, { componentId: 'a', value: 1, version: '0.1.0' }, { componentId: 'c' }] }).then(function (app) {
return _chai2.default.request(app).post('/components').send({ componentId: 'a', value: 2, ports: [{ port: 'in', kind: 'input', type: 'generic' }], version: '0.2.0' }).then(function (res) {
expect(res.status).to.equal(204);
}).then(function () {
return _chai2.default.request(app).get('/components/get/a');
}).then(function (res) {
return expect(res.body.value).to.equal(2);
});
});
});
});
};
var _chai = require('chai');
var _chai2 = _interopRequireDefault(_chai);
var _chaiHttp = require('chai-http');
var _chaiHttp2 = _interopRequireDefault(_chaiHttp);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }