@@ -17,6 +17,7 @@ var multi = require('./fixtures/multi-factory');
1717var dock = require ( './fixtures/dock' ) ;
1818var Runnable = require ( 'models/apis/runnable' ) ;
1919var PullRequest = require ( 'models/apis/pullrequest' ) ;
20+ var Github = require ( 'models/apis/github' ) ;
2021var cbCount = require ( 'callback-count' ) ;
2122
2223var nock = require ( 'nock' ) ;
@@ -293,6 +294,8 @@ describe('Github - /actions/github', function () {
293294
294295
295296 beforeEach ( function ( done ) {
297+ ctx . originalServerSelectionStatus = PullRequest . prototype . serverSelectionStatus ;
298+ ctx . originalGetPullRequestHeadCommit = Github . prototype . getPullRequestHeadCommit ;
296299 multi . createInstance ( function ( err , instance , build , user , modelsArr ) {
297300 ctx . contextVersion = modelsArr [ 0 ] ;
298301 ctx . context = modelsArr [ 1 ] ;
@@ -303,6 +306,47 @@ describe('Github - /actions/github', function () {
303306 } ) ;
304307 } ) ;
305308
309+ afterEach ( function ( done ) {
310+ PullRequest . prototype . serverSelectionStatus = ctx . originalServerSelectionStatus ;
311+ Github . prototype . getPullRequestHeadCommit = ctx . originalGetPullRequestHeadCommit ;
312+ done ( ) ;
313+ } ) ;
314+
315+ it ( 'should set server selection status for the branch without instance' , { timeout : 6000 } , function ( done ) {
316+
317+ Github . prototype . getPullRequestHeadCommit = function ( repo , number , cb ) {
318+ cb ( null , { commit : {
319+ message : 'hello'
320+ } } ) ;
321+ } ;
322+
323+ PullRequest . prototype . serverSelectionStatus = function ( pullRequest , targetUrl , cb ) {
324+ expect ( pullRequest . number ) . to . equal ( 2 ) ;
325+ expect ( pullRequest . headCommit . message ) . to . equal ( 'hello' ) ;
326+ expect ( pullRequest ) . to . exist ( ) ;
327+ expect ( targetUrl ) . to . include ( 'https://runnable.io/' ) ;
328+ expect ( targetUrl ) . to . include ( '/serverSelection/' ) ;
329+ cb ( ) ;
330+ done ( ) ;
331+ } ;
332+
333+ var acv = ctx . contextVersion . attrs . appCodeVersions [ 0 ] ;
334+ var data = {
335+ branch : 'feature-1' ,
336+ repo : acv . repo
337+ } ;
338+ var options = hooks ( data ) . pull_request_sync ;
339+ require ( './fixtures/mocks/github/users-username' ) ( 101 , 'podviaznikov' ) ;
340+ require ( './fixtures/mocks/docker/container-id-attach' ) ( ) ;
341+ request . post ( options , function ( err , res , contextVersionIds ) {
342+ if ( err ) { return done ( err ) ; }
343+ expect ( res . statusCode ) . to . equal ( 201 ) ;
344+ expect ( contextVersionIds ) . to . be . okay ;
345+ expect ( contextVersionIds ) . to . be . an ( 'array' ) ;
346+ expect ( contextVersionIds ) . to . have . a . lengthOf ( 1 ) ;
347+ } ) ;
348+ } ) ;
349+
306350 it ( 'should redeploy two instances with new build' , { timeout : 6000 } , function ( done ) {
307351 ctx . user . copyInstance ( ctx . instance . id ( ) , { } , function ( err , instance2 ) {
308352 if ( err ) { return done ( err ) ; }
0 commit comments