Skip to content

Commit b5225c3

Browse files
committed
Merge pull request #53 from VisualTesting/feature/services-array
Services is now an array of supported services
2 parents 9113d52 + cb37e9b commit b5225c3

7 files changed

Lines changed: 135 additions & 58 deletions

File tree

server/configuration.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var defaults = {
66
url: 'http://visualdiff.ngrok.com',
77
ip: '0.0.0.0',
88
port: 8999,
9-
service: undefined,
9+
services: [],
1010
differ: undefined,
1111
storage: undefined
1212
};
@@ -20,8 +20,8 @@ Configuration.prototype = {
2020
merge(this._config, newConfig);
2121
},
2222

23-
getService: function() {
24-
return this._config.service;
23+
getServices: function() {
24+
return this._config.services;
2525
},
2626

2727
getIp: function() {

server/controllers/api.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
var Bluebird = require('bluebird');
4-
// var assert = require('chai').assert;
54
var fs = Bluebird.promisifyAll(require('fs-extra'));
65

76
var actions = require('../actions');

server/serviceListener.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@ function setBuildStatus(options) {
1414
assert.isString(options.sha);
1515
assert.isString(options.status);
1616

17-
var service = config.getService();
18-
19-
if (service === undefined) {
17+
var services = config.getServices();
18+
if (services.length === 0) {
2019
return Bluebird.resolve();
2120
}
2221

2322
return storage.getProjectInfo(options.project)
2423
.then(function(info) {
25-
return service.setBuildStatus(info.service, {
26-
sha: options.sha,
27-
status: options.status
28-
});
24+
return Bluebird.any(
25+
services.map(function(service) {
26+
if (service.serviceKey === info.service.name) {
27+
return service.setBuildStatus(info.service, {
28+
sha: options.sha,
29+
status: options.status
30+
});
31+
}
32+
})
33+
);
2934
});
3035
}
3136

@@ -35,18 +40,23 @@ function addComment(options) {
3540
assert.isString(options.sha);
3641
assert.isString(options.comment);
3742

38-
var service = config.getService();
39-
40-
if (service === undefined) {
43+
var services = config.getServices();
44+
if (services.length === 0) {
4145
return Bluebird.resolve();
4246
}
4347

4448
return storage.getProjectInfo(options.project)
4549
.then(function(info) {
46-
return service.addComment(info.service, {
47-
sha: options.sha,
48-
comment: options.comment
49-
});
50+
return Bluebird.any(
51+
services.map(function(service) {
52+
if (service.serviceKey === info.service.name) {
53+
return service.addComment(info.service, {
54+
sha: options.sha,
55+
comment: options.comment
56+
});
57+
}
58+
})
59+
);
5060
});
5161
}
5262

server/utils/github.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var Github = require('./asyncGithub');
55

66
function verifyConfig(config) {
77
assert.isObject(config);
8-
assert.equal(config.name, 'github');
8+
assert.equal(config.name, GithubUtils.prototype.serviceKey());
99
assert.isObject(config.options);
1010
assert.isString(config.options.user);
1111
assert.isString(config.options.repository);
@@ -22,6 +22,8 @@ function GithubUtils(options) {
2222
}
2323

2424
GithubUtils.prototype = {
25+
serviceKey: 'github',
26+
2527
setBuildStatus: function(config, options) {
2628
verifyConfig(config);
2729

test/configuration-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ describe('module/configuration', function() {
1616
it('should not share state with a second instance', function() {
1717
var config2 = new Configuration();
1818
config.set({
19-
service: 'foo'
19+
port: '2000'
2020
});
2121

22-
assert.notEqual(config.getService(), config2.getService());
22+
assert.notEqual(config.getPort(), config2.getPort());
2323
});
2424
});

test/serviceListener-test.js

Lines changed: 102 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ describe('module/serviceListener', function() {
9595
});
9696

9797
describe('without a service', function() {
98+
beforeEach(function() {
99+
config.set({
100+
services: []
101+
});
102+
});
103+
98104
it('should resolve', function() {
99105
return assert.isFulfilled(serviceListener._setBuildStatus({
100106
project: 'project',
@@ -107,29 +113,56 @@ describe('module/serviceListener', function() {
107113
describe('with a service', function() {
108114
beforeEach(function() {
109115
config.set({
110-
service: fakeService
116+
services: [fakeService]
111117
});
112118
});
113119

114-
it('should call the service setBuildStatus', function() {
115-
storageStub.getProjectInfo = this.sinon.stub().resolves({
116-
service: projectConfig
120+
describe('that does not match the project config', function() {
121+
beforeEach(function() {
122+
fakeService.serviceKey = 'foo';
117123
});
118124

119-
return serviceListener._setBuildStatus({
120-
project: 'project',
121-
sha: 'sha',
122-
status: 'success'
123-
})
124-
.then(function() {
125-
assert.calledWithExactly(
126-
fakeService.setBuildStatus,
127-
projectConfig,
128-
{
129-
sha: 'sha',
130-
status: 'success'
131-
}
132-
);
125+
it('should not call service setBuildStatus', function() {
126+
storageStub.getProjectInfo = this.sinon.stub().resolves({
127+
service: projectConfig
128+
});
129+
130+
return serviceListener._setBuildStatus({
131+
project: 'project',
132+
sha: 'sha',
133+
status: 'success'
134+
})
135+
.then(function() {
136+
assert.notCalled(fakeService.setBuildStatus);
137+
});
138+
});
139+
});
140+
141+
describe('that matches the project config', function() {
142+
beforeEach(function() {
143+
fakeService.serviceKey = 'github';
144+
});
145+
146+
it('should call the service setBuildStatus', function() {
147+
storageStub.getProjectInfo = this.sinon.stub().resolves({
148+
service: projectConfig
149+
});
150+
151+
return serviceListener._setBuildStatus({
152+
project: 'project',
153+
sha: 'sha',
154+
status: 'success'
155+
})
156+
.then(function() {
157+
assert.calledWithExactly(
158+
fakeService.setBuildStatus,
159+
projectConfig,
160+
{
161+
sha: 'sha',
162+
status: 'success'
163+
}
164+
);
165+
});
133166
});
134167
});
135168
});
@@ -166,6 +199,12 @@ describe('module/serviceListener', function() {
166199
});
167200

168201
describe('without a service', function() {
202+
beforeEach(function() {
203+
config.set({
204+
services: []
205+
});
206+
});
207+
169208
it('should resolve', function() {
170209
return assert.isFulfilled(serviceListener._addComment({
171210
project: 'project',
@@ -178,29 +217,56 @@ describe('module/serviceListener', function() {
178217
describe('with a service', function() {
179218
beforeEach(function() {
180219
config.set({
181-
service: fakeService
220+
services: [fakeService]
182221
});
183222
});
184223

185-
it('should call the service addComment', function() {
186-
storageStub.getProjectInfo = this.sinon.stub().resolves({
187-
service: projectConfig
224+
describe('that does not match the project config', function() {
225+
beforeEach(function() {
226+
fakeService.serviceKey = 'foo';
188227
});
189228

190-
return serviceListener._addComment({
191-
project: 'project',
192-
sha: 'sha',
193-
comment: 'comment'
194-
})
195-
.then(function() {
196-
assert.calledWithExactly(
197-
fakeService.addComment,
198-
projectConfig,
199-
{
200-
sha: 'sha',
201-
comment: 'comment'
202-
}
203-
);
229+
it('should not call addComment', function() {
230+
storageStub.getProjectInfo = this.sinon.stub().resolves({
231+
service: projectConfig
232+
});
233+
234+
return serviceListener._addComment({
235+
project: 'project',
236+
sha: 'sha',
237+
comment: 'comment'
238+
})
239+
.then(function() {
240+
assert.notCalled(fakeService.addComment);
241+
});
242+
});
243+
});
244+
245+
describe('that matches the project config', function() {
246+
beforeEach(function() {
247+
fakeService.serviceKey = 'github';
248+
});
249+
250+
it('should call the service addComment', function() {
251+
storageStub.getProjectInfo = this.sinon.stub().resolves({
252+
service: projectConfig
253+
});
254+
255+
return serviceListener._addComment({
256+
project: 'project',
257+
sha: 'sha',
258+
comment: 'comment'
259+
})
260+
.then(function() {
261+
assert.calledWithExactly(
262+
fakeService.addComment,
263+
projectConfig,
264+
{
265+
sha: 'sha',
266+
comment: 'comment'
267+
}
268+
);
269+
});
204270
});
205271
});
206272
});

visualtesting.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function Apply(config) {
1616
config.set({
1717
port: 9000,
1818

19-
service: service,
19+
services: [service],
2020

2121
differ: Differ,
2222
storage: storage

0 commit comments

Comments
 (0)