@@ -343,88 +343,47 @@ describe('Github - /actions/github', function () {
343343
344344 describe ( 'push follow branch' , function ( ) {
345345 var ctx = { } ;
346+
346347 before ( function ( done ) {
347348 process . env . ENABLE_NEW_BRANCH_BUILDS_ON_GIT_PUSH = 'true' ;
348- done ( ) ;
349- } ) ;
350-
351-
352- beforeEach ( function ( done ) {
353349 multi . createInstance ( function ( err , instance , build , user , modelsArr ) {
354350 ctx . contextVersion = modelsArr [ 0 ] ;
355351 ctx . context = modelsArr [ 1 ] ;
356352 ctx . build = build ;
357353 ctx . user = user ;
358354 ctx . instance = instance ;
359- done ( err ) ;
360- } ) ;
361- } ) ;
362-
363- it ( 'should create new build, build it and deploy on instance' , { timeout : 3000 } , function ( done ) {
364- var acv = ctx . contextVersion . attrs . appCodeVersions [ 0 ] ;
365- var data = {
366- branch : 'master' ,
367- repo : acv . repo
368- } ;
369- var options = hooks ( data ) . push ;
370- require ( './fixtures/mocks/github/users-username' ) ( 101 , 'podviaznikov' ) ;
371- require ( './fixtures/mocks/docker/container-id-attach' ) ( ) ;
372- request . post ( options , function ( err , res , instances ) {
373- if ( err ) { return done ( err ) ; }
374- expect ( res . statusCode ) . to . equal ( 201 ) ;
375- expect ( instances ) . to . be . okay ;
376- expect ( instances ) . to . be . an ( 'array' ) ;
377- expect ( instances ) . to . have . a . lengthOf ( 1 ) ;
378- expect ( instances [ 0 ] . shortHash ) . to . equal ( ctx . instance . id ( ) ) ;
379- setTimeout ( function ( ) {
380- var expected = {
381- 'contextVersion.build.started' : exists ,
382- 'contextVersion.build.completed' : exists ,
383- 'contextVersion.build.duration' : exists ,
384- 'contextVersion.build.triggeredBy.github' : exists ,
385- 'contextVersion.appCodeVersions[0].lowerRepo' : options . json . repository . full_name ,
386- 'contextVersion.appCodeVersions[0].commit' : options . json . head_commit . id ,
387- 'contextVersion.appCodeVersions[0].branch' : data . branch ,
388- 'contextVersion.build.triggeredAction.manual' : false ,
389- 'contextVersion.build.triggeredAction.appCodeVersion.repo' :
390- options . json . repository . full_name ,
391- 'contextVersion.build.triggeredAction.appCodeVersion.commit' :
392- options . json . head_commit . id ,
393- 'contextVersion.build.triggeredAction.appCodeVersion.commitLog' :
394- function ( commitLog ) {
395- expect ( commitLog ) . to . be . an ( 'array' ) ;
396- expect ( commitLog ) . to . have . lengthOf ( 1 ) ;
397- expect ( commitLog [ 0 ] . id ) . to . equal ( options . json . head_commit . id ) ;
398- return true ;
399- }
400- } ;
401- ctx . instance . fetch ( expects . success ( 200 , expected , done ) ) ;
402- } , 1000 ) ;
355+ var settings = {
356+ owner : {
357+ github : instance . attrs . owner . github
358+ } ,
359+ notifications : {
360+ slack : {
361+ webhookUrl : 'http://slack.com/some-web-hook-url'
362+ } ,
363+ hipchat : {
364+ authToken : 'some-hipchat-token' ,
365+ roomId : 123123
366+ }
367+ }
368+ } ;
369+ user . createSetting ( { json : settings } , done ) ;
403370 } ) ;
404371 } ) ;
405372
406373 it ( 'should redeploy two instances with new build' , { timeout : 6000 } , function ( done ) {
407-
408374 ctx . user . copyInstance ( ctx . instance . id ( ) , { } , function ( err , instance2 ) {
409375 if ( err ) { return done ( err ) ; }
410- var acv = ctx . contextVersion . attrs . appCodeVersions [ 0 ] ;
411- var data = {
412- branch : 'master' ,
413- repo : acv . repo
414- } ;
415- var options = hooks ( data ) . push ;
416- require ( './fixtures/mocks/github/users-username' ) ( 101 , 'podviaznikov' ) ;
417- require ( './fixtures/mocks/docker/container-id-attach' ) ( ) ;
418- request . post ( options , function ( err , res , instances ) {
419- if ( err ) { return done ( err ) ; }
420- expect ( res . statusCode ) . to . equal ( 201 ) ;
421- expect ( instances ) . to . be . okay ;
422- expect ( instances ) . to . be . an ( 'array' ) ;
423- expect ( instances ) . to . have . a . lengthOf ( 2 ) ;
424- expect ( instances [ 0 ] . shortHash ) . to . equal ( ctx . instance . id ( ) ) ;
425- expect ( instances [ 1 ] . shortHash ) . to . equal ( instance2 . shortHash ) ;
426376
427- setTimeout ( function ( ) {
377+ var spyOnClassMethod = require ( 'function-proxy' ) . spyOnClassMethod ;
378+ spyOnClassMethod ( require ( 'models/notifications/index' ) , 'notifyOnInstances' ,
379+ function ( githubPushInfo , deployedInstances ) {
380+ expect ( deployedInstances ) . to . be . okay ;
381+ expect ( deployedInstances ) . to . be . an ( 'array' ) ;
382+ expect ( deployedInstances ) . to . have . a . lengthOf ( 2 ) ;
383+ var hashes = [ deployedInstances [ 0 ] . shortHash , deployedInstances [ 1 ] . shortHash ] ;
384+ expect ( hashes ) . to . include ( ctx . instance . id ( ) ) ;
385+ expect ( hashes ) . to . include ( instance2 . shortHash ) ;
386+ expect ( githubPushInfo . commitLog ) . to . have . a . lengthOf ( 1 ) ;
428387 var expected = {
429388 'contextVersion.build.started' : exists ,
430389 'contextVersion.build.completed' : exists ,
@@ -446,12 +405,29 @@ describe('Github - /actions/github', function () {
446405 return true ;
447406 }
448407 } ;
449-
450408 ctx . instance . fetch ( expects . success ( 200 , expected , function ( err ) {
451409 if ( err ) { return done ( err ) ; }
452410 ctx . user . newInstance ( instance2 . shortHash ) . fetch ( expects . success ( 200 , expected , done ) ) ;
453411 } ) ) ;
454- } , 1000 ) ;
412+ } ) ;
413+
414+
415+ var acv = ctx . contextVersion . attrs . appCodeVersions [ 0 ] ;
416+ var data = {
417+ branch : 'master' ,
418+ repo : acv . repo
419+ } ;
420+ var options = hooks ( data ) . push ;
421+ require ( './fixtures/mocks/github/users-username' ) ( 101 , 'podviaznikov' ) ;
422+ require ( './fixtures/mocks/docker/container-id-attach' ) ( ) ;
423+ request . post ( options , function ( err , res , instances ) {
424+ if ( err ) { return done ( err ) ; }
425+ expect ( res . statusCode ) . to . equal ( 201 ) ;
426+ expect ( instances ) . to . be . okay ;
427+ expect ( instances ) . to . be . an ( 'array' ) ;
428+ expect ( instances ) . to . have . a . lengthOf ( 2 ) ;
429+ expect ( instances [ 0 ] . shortHash ) . to . equal ( ctx . instance . id ( ) ) ;
430+ expect ( instances [ 1 ] . shortHash ) . to . equal ( instance2 . shortHash ) ;
455431 } ) ;
456432 } ) ;
457433 } ) ;
0 commit comments