From b53099ec465fec22e08ef290e22b4e8787ed3c86 Mon Sep 17 00:00:00 2001 From: Eli White Date: Wed, 8 Apr 2015 12:56:09 -0700 Subject: [PATCH] Create project now accepts services that have been set via configuration --- server/configuration.js | 6 ++++++ server/controllers/api.js | 2 +- test/api-test.js | 35 ++++++++++++++++++++++++++++++++- test/configuration-test.js | 40 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) diff --git a/server/configuration.js b/server/configuration.js index d6fd5e9..17abe2e 100644 --- a/server/configuration.js +++ b/server/configuration.js @@ -24,6 +24,12 @@ Configuration.prototype = { return this._config.services; }, + getSupportedServices: function() { + return this._config.services.map(function(service) { + return service.serviceKey; + }); + }, + getIp: function() { return this._config.ip; }, diff --git a/server/controllers/api.js b/server/controllers/api.js index a312309..de0c138 100644 --- a/server/controllers/api.js +++ b/server/controllers/api.js @@ -39,7 +39,7 @@ Api.prototype = { return; } - if (service.name !== 'github') { + if (configuration.getSupportedServices().indexOf(service.name) === -1) { res.status(400).json({ status: 'failure', message: 'unsupported dvcs' diff --git a/test/api-test.js b/test/api-test.js index d239aca..d23362e 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -9,6 +9,8 @@ var fs = Bluebird.promisifyAll(require('fs-extra')); var TarHelper = require('../server/utils/tar-helper'); describe('module/api', function() { + var config; + var storageStub; var actionsStub; var api; @@ -42,7 +44,7 @@ describe('module/api', function() { var app = new App(); var Configuration = require('../server/configuration'); - var config = new Configuration(); + config = new Configuration(); config.set({ storage: storageStub }); @@ -69,7 +71,32 @@ describe('module/api', function() { }); }); + it('should fail with no installed dvcs', function() { + return instance.send({ + service: { + name: 'bad', + options: { + user: 'user', + repository: 'repo' + } + } + }) + .expect(400) + .expect(function(data) { + var body = data.body; + + assert.equal(body.status, 'failure'); + assert.equal(body.message, 'unsupported dvcs'); + }); + }); + it('should fail when not given recognized dvcs', function() { + config.set({ + services: [{ + serviceKey: 'github' + }] + }); + return instance.send({ service: { name: 'bad', @@ -93,6 +120,12 @@ describe('module/api', function() { var projectOptions; beforeEach(function() { + config.set({ + services: [{ + serviceKey: 'github' + }] + }); + projectOptions = { service: { name: 'github', diff --git a/test/configuration-test.js b/test/configuration-test.js index ae33cd2..9abcae7 100644 --- a/test/configuration-test.js +++ b/test/configuration-test.js @@ -21,4 +21,44 @@ describe('module/configuration', function() { assert.notEqual(config.getPort(), config2.getPort()); }); + + describe('#getSupportedServices', function() { + it('should be empty with no services', function() { + config.set({ + services: [] + }); + + assert.equal(config.getSupportedServices().length, 0); + }); + + it('should return array of serviceKey if one service', function() { + config.set({ + services: [{ + serviceKey: 'service1' + }] + }); + + var keys = config.getSupportedServices(); + assert.equal(keys.length, 1); + assert.equal(keys[0], 'service1'); + }); + + it('should return array of serviceKey with multiple services', function() { + config.set({ + services: [{ + serviceKey: 'service1' + }, + { + serviceKey: 'service2' + }, + { + serviceKey: 'service3' + }] + }); + + var keys = config.getSupportedServices(); + assert.equal(keys.length, 3); + assert.sameMembers(keys, ['service1', 'service2', 'service3']); + }); + }); });