Skip to content

Commit 90c41f3

Browse files
committed
Merge pull request #63 from VisualTesting/feature/allow-dvcs
Create project now accepts services that have been set via configuration
2 parents 83da393 + b53099e commit 90c41f3

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

server/configuration.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Configuration.prototype = {
2424
return this._config.services;
2525
},
2626

27+
getSupportedServices: function() {
28+
return this._config.services.map(function(service) {
29+
return service.serviceKey;
30+
});
31+
},
32+
2733
getIp: function() {
2834
return this._config.ip;
2935
},

server/controllers/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Api.prototype = {
3939
return;
4040
}
4141

42-
if (service.name !== 'github') {
42+
if (configuration.getSupportedServices().indexOf(service.name) === -1) {
4343
res.status(400).json({
4444
status: 'failure',
4545
message: 'unsupported dvcs'

test/api-test.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var fs = Bluebird.promisifyAll(require('fs-extra'));
99
var TarHelper = require('../server/utils/tar-helper');
1010

1111
describe('module/api', function() {
12+
var config;
13+
1214
var storageStub;
1315
var actionsStub;
1416
var api;
@@ -42,7 +44,7 @@ describe('module/api', function() {
4244

4345
var app = new App();
4446
var Configuration = require('../server/configuration');
45-
var config = new Configuration();
47+
config = new Configuration();
4648
config.set({
4749
storage: storageStub
4850
});
@@ -69,7 +71,32 @@ describe('module/api', function() {
6971
});
7072
});
7173

74+
it('should fail with no installed dvcs', function() {
75+
return instance.send({
76+
service: {
77+
name: 'bad',
78+
options: {
79+
user: 'user',
80+
repository: 'repo'
81+
}
82+
}
83+
})
84+
.expect(400)
85+
.expect(function(data) {
86+
var body = data.body;
87+
88+
assert.equal(body.status, 'failure');
89+
assert.equal(body.message, 'unsupported dvcs');
90+
});
91+
});
92+
7293
it('should fail when not given recognized dvcs', function() {
94+
config.set({
95+
services: [{
96+
serviceKey: 'github'
97+
}]
98+
});
99+
73100
return instance.send({
74101
service: {
75102
name: 'bad',
@@ -93,6 +120,12 @@ describe('module/api', function() {
93120
var projectOptions;
94121

95122
beforeEach(function() {
123+
config.set({
124+
services: [{
125+
serviceKey: 'github'
126+
}]
127+
});
128+
96129
projectOptions = {
97130
service: {
98131
name: 'github',

test/configuration-test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,44 @@ describe('module/configuration', function() {
2121

2222
assert.notEqual(config.getPort(), config2.getPort());
2323
});
24+
25+
describe('#getSupportedServices', function() {
26+
it('should be empty with no services', function() {
27+
config.set({
28+
services: []
29+
});
30+
31+
assert.equal(config.getSupportedServices().length, 0);
32+
});
33+
34+
it('should return array of serviceKey if one service', function() {
35+
config.set({
36+
services: [{
37+
serviceKey: 'service1'
38+
}]
39+
});
40+
41+
var keys = config.getSupportedServices();
42+
assert.equal(keys.length, 1);
43+
assert.equal(keys[0], 'service1');
44+
});
45+
46+
it('should return array of serviceKey with multiple services', function() {
47+
config.set({
48+
services: [{
49+
serviceKey: 'service1'
50+
},
51+
{
52+
serviceKey: 'service2'
53+
},
54+
{
55+
serviceKey: 'service3'
56+
}]
57+
});
58+
59+
var keys = config.getSupportedServices();
60+
assert.equal(keys.length, 3);
61+
assert.sameMembers(keys, ['service1', 'service2', 'service3']);
62+
});
63+
});
2464
});

0 commit comments

Comments
 (0)