Skip to content

Commit 9298286

Browse files
committed
add tests for server selection case
1 parent 6e9ec66 commit 9298286

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/routes/actions/github.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ function notServersForPullRequest () {
135135
mw.req().set('contextOwner', 'user'),
136136
github.create({token: 'versionCreator.accounts.github.accessToken'}),
137137
github.model.getPullRequestHeadCommit('githubPullRequest.repo', 'githubPullRequest.number'),
138-
139138
mw.req().set('githubPullRequest.headCommit', 'githubResult.commit'),
140139
function (req, res, next) {
141140
var selectionUrl = createServerSelectionUrl(req.contextOwner.login, req.githubPullRequest);

test/actions-github.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var multi = require('./fixtures/multi-factory');
1717
var dock = require('./fixtures/dock');
1818
var Runnable = require('models/apis/runnable');
1919
var PullRequest = require('models/apis/pullrequest');
20+
var Github = require('models/apis/github');
2021
var cbCount = require('callback-count');
2122

2223
var 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

Comments
 (0)