diff --git a/lib/routes/actions/github.js b/lib/routes/actions/github.js index fdca63abe..fad450822 100644 --- a/lib/routes/actions/github.js +++ b/lib/routes/actions/github.js @@ -300,9 +300,8 @@ function followBranch (instancesKey) { function (instance, req, eachReq, res, next) { if (eachReq.instanceDeployed) { req.deployedInstances.push(instance); - } else { - next(); } + next(); } ), mw.req('deployedInstances.length').validate(validations.notEquals(0)) diff --git a/test/actions-github.js b/test/actions-github.js index 19778ab6b..1e0c81c5a 100644 --- a/test/actions-github.js +++ b/test/actions-github.js @@ -343,88 +343,47 @@ describe('Github - /actions/github', function () { describe('push follow branch', function () { var ctx = {}; + before(function (done) { process.env.ENABLE_NEW_BRANCH_BUILDS_ON_GIT_PUSH = 'true'; - done(); - }); - - - beforeEach(function (done) { multi.createInstance(function (err, instance, build, user, modelsArr) { ctx.contextVersion = modelsArr[0]; ctx.context = modelsArr[1]; ctx.build = build; ctx.user = user; ctx.instance = instance; - done(err); - }); - }); - - it('should create new build, build it and deploy on instance', {timeout: 3000}, function (done) { - var acv = ctx.contextVersion.attrs.appCodeVersions[0]; - var data = { - branch: 'master', - repo: acv.repo - }; - var options = hooks(data).push; - require('./fixtures/mocks/github/users-username')(101, 'podviaznikov'); - require('./fixtures/mocks/docker/container-id-attach')(); - request.post(options, function (err, res, instances) { - if (err) { return done(err); } - expect(res.statusCode).to.equal(201); - expect(instances).to.be.okay; - expect(instances).to.be.an('array'); - expect(instances).to.have.a.lengthOf(1); - expect(instances[0].shortHash).to.equal(ctx.instance.id()); - setTimeout(function () { - var expected = { - 'contextVersion.build.started': exists, - 'contextVersion.build.completed': exists, - 'contextVersion.build.duration': exists, - 'contextVersion.build.triggeredBy.github': exists, - 'contextVersion.appCodeVersions[0].lowerRepo': options.json.repository.full_name, - 'contextVersion.appCodeVersions[0].commit': options.json.head_commit.id, - 'contextVersion.appCodeVersions[0].branch': data.branch, - 'contextVersion.build.triggeredAction.manual': false, - 'contextVersion.build.triggeredAction.appCodeVersion.repo': - options.json.repository.full_name, - 'contextVersion.build.triggeredAction.appCodeVersion.commit': - options.json.head_commit.id, - 'contextVersion.build.triggeredAction.appCodeVersion.commitLog': - function (commitLog) { - expect(commitLog).to.be.an('array'); - expect(commitLog).to.have.lengthOf(1); - expect(commitLog[0].id).to.equal(options.json.head_commit.id); - return true; - } - }; - ctx.instance.fetch(expects.success(200, expected, done)); - }, 1000); + var settings = { + owner: { + github: instance.attrs.owner.github + }, + notifications: { + slack: { + webhookUrl: 'http://slack.com/some-web-hook-url' + }, + hipchat: { + authToken: 'some-hipchat-token', + roomId: 123123 + } + } + }; + user.createSetting({json: settings}, done); }); }); it('should redeploy two instances with new build', {timeout: 6000}, function (done) { - ctx.user.copyInstance(ctx.instance.id(), {}, function (err, instance2) { if (err) { return done(err); } - var acv = ctx.contextVersion.attrs.appCodeVersions[0]; - var data = { - branch: 'master', - repo: acv.repo - }; - var options = hooks(data).push; - require('./fixtures/mocks/github/users-username')(101, 'podviaznikov'); - require('./fixtures/mocks/docker/container-id-attach')(); - request.post(options, function (err, res, instances) { - if (err) { return done(err); } - expect(res.statusCode).to.equal(201); - expect(instances).to.be.okay; - expect(instances).to.be.an('array'); - expect(instances).to.have.a.lengthOf(2); - expect(instances[0].shortHash).to.equal(ctx.instance.id()); - expect(instances[1].shortHash).to.equal(instance2.shortHash); - setTimeout(function () { + var spyOnClassMethod = require('function-proxy').spyOnClassMethod; + spyOnClassMethod(require('models/notifications/index'), 'notifyOnInstances', + function (githubPushInfo, deployedInstances) { + expect(deployedInstances).to.be.okay; + expect(deployedInstances).to.be.an('array'); + expect(deployedInstances).to.have.a.lengthOf(2); + var hashes = [deployedInstances[0].shortHash, deployedInstances[1].shortHash]; + expect(hashes).to.include(ctx.instance.id()); + expect(hashes).to.include(instance2.shortHash); + expect(githubPushInfo.commitLog).to.have.a.lengthOf(1); var expected = { 'contextVersion.build.started': exists, 'contextVersion.build.completed': exists, @@ -446,12 +405,29 @@ describe('Github - /actions/github', function () { return true; } }; - ctx.instance.fetch(expects.success(200, expected, function (err) { if (err) { return done(err); } ctx.user.newInstance(instance2.shortHash).fetch(expects.success(200, expected, done)); })); - }, 1000); + }); + + + var acv = ctx.contextVersion.attrs.appCodeVersions[0]; + var data = { + branch: 'master', + repo: acv.repo + }; + var options = hooks(data).push; + require('./fixtures/mocks/github/users-username')(101, 'podviaznikov'); + require('./fixtures/mocks/docker/container-id-attach')(); + request.post(options, function (err, res, instances) { + if (err) { return done(err); } + expect(res.statusCode).to.equal(201); + expect(instances).to.be.okay; + expect(instances).to.be.an('array'); + expect(instances).to.have.a.lengthOf(2); + expect(instances[0].shortHash).to.equal(ctx.instance.id()); + expect(instances[1].shortHash).to.equal(instance2.shortHash); }); }); });