Skip to content

Commit

Permalink
Merge pull request #63 from VisualTesting/feature/allow-dvcs
Browse files Browse the repository at this point in the history
Create project now accepts services that have been set via configuration
  • Loading branch information
elicwhite committed Apr 8, 2015
2 parents 83da393 + b53099e commit 90c41f3
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
6 changes: 6 additions & 0 deletions server/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
35 changes: 34 additions & 1 deletion test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
});
Expand All @@ -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',
Expand All @@ -93,6 +120,12 @@ describe('module/api', function() {
var projectOptions;

beforeEach(function() {
config.set({
services: [{
serviceKey: 'github'
}]
});

projectOptions = {
service: {
name: 'github',
Expand Down
40 changes: 40 additions & 0 deletions test/configuration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
});
});

0 comments on commit 90c41f3

Please sign in to comment.