@@ -110,6 +110,7 @@ describe('build plugin test', () => {
110
110
} ) ) ;
111
111
server . auth . strategy ( 'token' , 'custom' ) ;
112
112
server . auth . strategy ( 'session' , 'custom' ) ;
113
+ server . event ( 'build_status' ) ;
113
114
114
115
secretMock = {
115
116
register : ( s , o , next ) => {
@@ -181,7 +182,15 @@ describe('build plugin test', () => {
181
182
182
183
describe ( 'PUT /builds/{id}' , ( ) => {
183
184
const id = 12345 ;
185
+ const pipelineId = 123 ;
186
+ const scmUri = 'github.com:12345:branchName' ;
187
+ const scmRepo = {
188
+ branch : 'master' ,
189
+ name : 'screwdriver-cd/screwdriver' ,
190
+ url : 'https://github.com/screwdriver-cd/screwdriver/tree/branchName'
191
+ } ;
184
192
let buildMock ;
193
+ let pipelineMock ;
185
194
186
195
beforeEach ( ( ) => {
187
196
testBuild . status = 'QUEUED' ;
@@ -193,6 +202,62 @@ describe('build plugin test', () => {
193
202
194
203
buildFactoryMock . get . resolves ( buildMock ) ;
195
204
buildMock . update . resolves ( buildMock ) ;
205
+
206
+ pipelineMock = {
207
+ id : pipelineId ,
208
+ scmUri,
209
+ scmRepo,
210
+ sync : sinon . stub ( ) . resolves ( )
211
+ } ;
212
+ } ) ;
213
+
214
+ it ( 'emits event buid_status' , ( ) => {
215
+ const jobMock = {
216
+ id : 1234 ,
217
+ name : 'main' ,
218
+ pipelineId,
219
+ permutations : [ {
220
+ settings : {
221
+ email : 'foo@bar.com'
222
+ }
223
+ } ]
224
+ } ;
225
+
226
+ jobMock . pipeline = sinon . stub ( ) . resolves ( pipelineMock ) ( ) ;
227
+ buildMock . job = sinon . stub ( ) . resolves ( jobMock ) ( ) ;
228
+ buildMock . settings = {
229
+ email : 'foo@bar.com'
230
+ } ;
231
+
232
+ buildFactoryMock . get . resolves ( buildMock ) ;
233
+ buildFactoryMock . uiUri = 'http://foo.bar' ;
234
+
235
+ const options = {
236
+ method : 'PUT' ,
237
+ url : `/builds/${ id } ` ,
238
+ payload : {
239
+ status : 'ABORTED'
240
+ } ,
241
+ credentials : {
242
+ scope : [ 'user' ]
243
+ }
244
+ } ;
245
+
246
+ server . emit = sinon . stub ( ) . resolves ( null ) ;
247
+
248
+ return server . inject ( options ) . then ( ( reply ) => {
249
+ assert . calledWith ( server . emit , 'build_status' , {
250
+ buildId : 12345 ,
251
+ buildLink : 'http://foo.bar/builds/12345' ,
252
+ jobName : 'main' ,
253
+ pipelineName : 'screwdriver-cd/screwdriver' ,
254
+ settings : {
255
+ email : 'foo@bar.com'
256
+ } ,
257
+ status : 'ABORTED'
258
+ } ) ;
259
+ assert . equal ( reply . statusCode , 200 ) ;
260
+ } ) ;
196
261
} ) ;
197
262
198
263
it ( 'returns 404 for updating a build that does not exist' , ( ) => {
@@ -235,6 +300,22 @@ describe('build plugin test', () => {
235
300
236
301
describe ( 'user token' , ( ) => {
237
302
it ( 'returns 200 for updating a build that exists' , ( ) => {
303
+ const jobMock = {
304
+ id : 1234 ,
305
+ name : 'main' ,
306
+ pipelineId,
307
+ permutations : [ {
308
+ settings : {
309
+ email : 'foo@bar.com'
310
+ }
311
+ } ]
312
+ } ;
313
+
314
+ jobMock . pipeline = sinon . stub ( ) . resolves ( pipelineMock ) ( ) ;
315
+ buildMock . job = sinon . stub ( ) . resolves ( jobMock ) ( ) ;
316
+
317
+ buildFactoryMock . get . resolves ( buildMock ) ;
318
+
238
319
const expected = hoek . applyToDefaults ( testBuild , { status : 'ABORTED' } ) ;
239
320
const options = {
240
321
method : 'PUT' ,
@@ -250,9 +331,9 @@ describe('build plugin test', () => {
250
331
buildMock . toJson . returns ( expected ) ;
251
332
252
333
return server . inject ( options ) . then ( ( reply ) => {
253
- assert . equal ( reply . statusCode , 200 ) ;
254
334
assert . deepEqual ( reply . result , expected ) ;
255
335
assert . calledWith ( buildFactoryMock . get , id ) ;
336
+ assert . equal ( reply . statusCode , 200 ) ;
256
337
} ) ;
257
338
} ) ;
258
339
@@ -296,23 +377,18 @@ describe('build plugin test', () => {
296
377
297
378
describe ( 'build token' , ( ) => {
298
379
const jobId = 1234 ;
299
- const pipelineId = 123 ;
300
380
const publishJobId = 1235 ;
301
- const scmUri = 'github.com:12345:branchName' ;
302
381
303
382
let jobMock ;
304
- let pipelineMock ;
305
383
306
384
beforeEach ( ( ) => {
307
385
jobMock = {
308
386
id : jobId ,
309
387
name : 'main' ,
310
- pipelineId
311
- } ;
312
- pipelineMock = {
313
- id : pipelineId ,
314
- scmUri,
315
- sync : sinon . stub ( ) . resolves ( )
388
+ pipelineId,
389
+ permutations : [ {
390
+ settings : { }
391
+ } ]
316
392
} ;
317
393
318
394
jobMock . pipeline = sinon . stub ( ) . resolves ( pipelineMock ) ( ) ;
0 commit comments