@@ -250,19 +250,94 @@ describe('index', () => {
250250 creator : { username : 'foo' } ,
251251 commit : {
252252 author : { name : 'foo' } ,
253- message : 'fixing a bug'
253+ message : 'fixing a bug' ,
254+ url : 'http://scmtest/org/repo/commit/123456'
254255 } ,
255256 sha : '1234567890abcdeffedcba098765432100000000'
256257 } ,
257258 buildLink : 'http://thisisaSDtest.com/pipelines/12/builds/1234'
258259 } ;
259260
261+ const postMessagePayloadData = {
262+ channel : 'meeseeks' ,
263+ text : '*FAILURE* :umbrella: <http://thisisaSDtest.com/pipelines/12|screwdriver-cd/notifications publish>' ,
264+ as_user : true ,
265+ attachments : [
266+ {
267+ fallback : '' ,
268+ color : 'danger' ,
269+ title : '#1234' ,
270+ title_link : 'http://thisisaSDtest.com/pipelines/12/builds/1234' ,
271+ text :
272+ 'fixing a bug (<http://scmtest/org/repo/commit/123456|123456>)\n' +
273+ 'Merge pull request #26 from screwdriver-cd/notifications'
274+ }
275+ ]
276+ } ;
277+
260278 serverMock . event ( eventMock ) ;
261279 serverMock . events . on ( eventMock , data => notifier . notify ( eventMock , data ) ) ;
262280 serverMock . events . emit ( eventMock , buildDataMockSimple ) ;
263281
264282 process . nextTick ( ( ) => {
265- assert . calledOnce ( WebClientMock . chat . postMessage ) ;
283+ assert . calledWith ( WebClientMock . chat . postMessage , postMessagePayloadData ) ;
284+ done ( ) ;
285+ } ) ;
286+ } ) ;
287+
288+ it ( 'sets channels and statuses for simple slack string name for PR builds.' , done => {
289+ const buildDataMockSimple = {
290+ settings : {
291+ slack : 'meeseeks'
292+ } ,
293+ status : 'FAILURE' ,
294+ pipeline : {
295+ id : '123' ,
296+ scmRepo : {
297+ name : 'screwdriver-cd/notifications'
298+ }
299+ } ,
300+ jobName : 'PR-1:publish' ,
301+ build : {
302+ id : '1234'
303+ } ,
304+ event : {
305+ id : '12345' ,
306+ causeMessage : 'Merge pull request #26 from screwdriver-cd/notifications' ,
307+ creator : { username : 'foo' } ,
308+ commit : {
309+ author : { name : 'foo' } ,
310+ message : 'fixing a bug' ,
311+ url : 'http://scmtest/org/repo/commit/123456'
312+ } ,
313+ sha : '1234567890abcdeffedcba098765432100000000'
314+ } ,
315+ buildLink : 'http://thisisaSDtest.com/pipelines/12/builds/1234'
316+ } ;
317+
318+ const postMessagePayloadData = {
319+ channel : 'meeseeks' ,
320+ text : '*FAILURE* :umbrella: <http://thisisaSDtest.com/pipelines/12/pulls|screwdriver-cd/notifications PR-1:publish>' ,
321+ as_user : true ,
322+ attachments : [
323+ {
324+ fallback : '' ,
325+ color : 'danger' ,
326+ title : '#1234' ,
327+ title_link : 'http://thisisaSDtest.com/pipelines/12/builds/1234' ,
328+ text :
329+ 'fixing a bug (<http://scmtest/org/repo/commit/123456|123456>)\n' +
330+ 'Merge pull request #26 from screwdriver-cd/notifications'
331+ }
332+ ]
333+ } ;
334+
335+ serverMock . event ( eventMock ) ;
336+ serverMock . events . on ( eventMock , data => notifier . notify ( eventMock , data ) ) ;
337+ serverMock . events . emit ( eventMock , buildDataMockSimple ) ;
338+
339+ process . nextTick ( ( ) => {
340+ assert . calledWith ( WebClientMock . chat . postMessage , postMessagePayloadData ) ;
266341 done ( ) ;
267342 } ) ;
268343 } ) ;
0 commit comments