Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Building the initial web hook handling setup #9

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"scripts": {
"build": "ember build",
"start": "ember server",
"test": "ember test"
"test": "ember test",
"test-webhook": "node webhook-tests/nodetest-runner.js"
},
"repository": "",
"engines": {
Expand Down Expand Up @@ -43,6 +44,13 @@
"ember-normalize": "0.0.9",
"ember-pagefront": "0.10.10",
"ember-resolver": "^2.0.3",
"loader.js": "^4.0.0"
"glob": "^7.0.3",
"loader.js": "^4.0.0",
"mocha": "^2.4.5",
"mocha-only-detector": "^0.1.0",
"sinon": "^1.17.3"
},
"dependencies": {
"github-webhook-handler": "^0.5.0"
}
}
54 changes: 54 additions & 0 deletions webhook-tests/fixtures/labeled-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module.exports = {
"payload": {
"action": "unlabeled",
"issue": {
"html_url": "https://github.com/emberjs/ember.js/issues/1",
"number": 1,
"user": {
"login": "acorncom",
"id": 802505,
"avatar_url": "https://avatars.githubusercontent.com/u/802505?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/acorncom",
"html_url": "https://github.com/acorncom",
"followers_url": "https://api.github.com/users/acorncom/followers",
"following_url": "https://api.github.com/users/acorncom/following{/other_user}",
"gists_url": "https://api.github.com/users/acorncom/gists{/gist_id}",
"starred_url": "https://api.github.com/users/acorncom/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/acorncom/subscriptions",
"organizations_url": "https://api.github.com/users/acorncom/orgs",
"repos_url": "https://api.github.com/users/acorncom/repos",
"events_url": "https://api.github.com/users/acorncom/events{/privacy}",
"received_events_url": "https://api.github.com/users/acorncom/received_events",
"type": "User",
"site_admin": false
},
"labels": [
{
"url": "https://api.github.com/repos/emberjs/ember.js/labels/Needs%20Help",
"name": "Needs Help",
"color": "84b6eb"
}
],
"state": "open",
"title": "Testing issue",
"locked": false,
"assignee": null,
"milestone": null,
"comments": 0,
"created_at": "2016-04-23T20:27:21Z",
"updated_at": "2016-04-23T21:35:03Z",
"closed_at": null,
"body": "Setting this up"
},
"label": {
"url": "https://api.github.com/repos/acorncom/ember-hitlist-tester/labels/Help%20Wanted",
"name": "Help Wanted",
"color": "128A0C"
},
"repository": {
"full_name": "emberjs/ember.js",
"html_url": "https://github.com/emberjs/ember.js",
}
}
};
53 changes: 53 additions & 0 deletions webhook-tests/fixtures/unlabeled-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module.exports = {
"payload": {
"action": "unlabeled",
"issue": {
"html_url": "https://github.com/acorncom/ember-hitlist-tester/issues/1",
"number": 1,
"user": {
"login": "acorncom",
"id": 802505,
"avatar_url": "https://avatars.githubusercontent.com/u/802505?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/acorncom",
"html_url": "https://github.com/acorncom",
"followers_url": "https://api.github.com/users/acorncom/followers",
"following_url": "https://api.github.com/users/acorncom/following{/other_user}",
"gists_url": "https://api.github.com/users/acorncom/gists{/gist_id}",
"starred_url": "https://api.github.com/users/acorncom/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/acorncom/subscriptions",
"organizations_url": "https://api.github.com/users/acorncom/orgs",
"repos_url": "https://api.github.com/users/acorncom/repos",
"events_url": "https://api.github.com/users/acorncom/events{/privacy}",
"received_events_url": "https://api.github.com/users/acorncom/received_events",
"type": "User",
"site_admin": false
},
"labels": [
{
"url": "https://api.github.com/repos/acorncom/ember-hitlist-tester/labels/enhancement",
"name": "enhancement",
"color": "84b6eb"
}
],
"state": "open",
"locked": false,
"assignee": null,
"milestone": null,
"comments": 0,
"created_at": "2016-04-23T20:27:21Z",
"updated_at": "2016-04-23T21:35:03Z",
"closed_at": null,
"body": "Setting this up"
},
"label": {
"url": "https://api.github.com/repos/acorncom/ember-hitlist-tester/labels/Help%20Wanted",
"name": "Help Wanted",
"color": "128A0C"
},
"repository": {
"full_name": "emberjs/ember.js",
"html_url": "https://github.com/acorncom/ember-hitlist-tester",
}
}
};
57 changes: 57 additions & 0 deletions webhook-tests/nodetest-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

/*eslint no-console: 0 */

var glob = require('glob');
var Mocha = require('mocha');
var Promise = require('ember-cli/lib/ext/promise');
var mochaOnlyDetector = require('mocha-only-detector');

if (process.env.EOLNEWLINE) {
require('os').EOL = '\n';
}

var root = 'webhook-tests/{acceptance,unit}';
var _checkOnlyInTests = Promise.denodeify(mochaOnlyDetector.checkFolder.bind(null, root + '/**/*{-test}.js'));
var mocha = new Mocha({
timeout: 5000,
reporter: 'spec'
});
addFiles(mocha, glob.sync(root + '/**/*-test.js'));

function addFiles(mocha, files) {
files = (typeof files === 'string') ? glob.sync(root + files) : files;
files.forEach(mocha.addFile.bind(mocha));
}

function checkOnlyInTests() {
console.log('Verifing `.only` in tests');
return _checkOnlyInTests().then(function() {
console.log('No `.only` found');
});
}

function runMocha() {
mocha.run(function(failures) {
process.on('exit', function() {
process.exit(failures);
});
});
}

function ciVerificationStep() {
if (process.env.CI === 'true') {
return checkOnlyInTests();
} else {
return Promise.resolve();
}
}

ciVerificationStep()
.then(function() {
runMocha();
})
.catch(function(error) {
console.error(error.stack);
process.exit(1);
});
86 changes: 86 additions & 0 deletions webhook-tests/unit/issue-handler-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* jshint node: true */
/* jshint mocha: true */
'use strict';

var assert = require('assert');
var path = require('path');
var sinon = require('sinon');

var IssueHandler = require('../../webhook/issue-handler');
var fakeEvent = require('../fixtures/unlabeled-event');

describe('adding a label to an issue', function() {
var fakeEvent = require('../fixtures/labeled-event');

it('updates Firebase', function() {

var addIssue = sinon.spy(IssueHandler, 'addIssueToDatastore');
var expectedIssueHash = {
id: 1,
url: 'https://github.com/emberjs/ember.js/issues/1',
title: 'Testing issue',
labels: [{
"url": "https://api.github.com/repos/emberjs/ember.js/labels/Needs%20Help",
"name": "Needs Help",
"color": "84b6eb"
}],
repo: 'emberjs/ember.js',
repoUrl: 'https://github.com/emberjs/ember.js'
};

var result = IssueHandler.issueLabeled(fakeEvent);

addIssue.restore();
sinon.assert.calledWith(addIssue, expectedIssueHash);

assert.ok(result, 'issue not properly sent to Firebase');
});
});

describe('removing a label removes it from our Firebase list', function() {
it('updates Firebase', function() {

var result = IssueHandler.issueUnlabeled(fakeEvent);
assert.ok(false, 'Need to confirm that we send the right info to mocked Firebase function');
assert.ok(result, 'issue not properly removed');
});
});

describe('closing a label removes it from our Firebase list', function() {
it('updates Firebase', function () {
var result = IssueHandler.issueClosed(fakeEvent);
assert.ok(result, 'issue not properly removed');
assert.ok(false, 'Need to confirm that we send the right info to mocked Firebase function');
});
});
describe('reopening a label adds it to our Firebase list', function() {
it('updates Firebase', function () {
var result = IssueHandler.issueReopened(fakeEvent);
assert.ok(result, 'issue not properly reopened');
assert.ok(false, 'Need to confirm that we send the right info to mocked Firebase function');
});
});

describe('renaming an issue updates its title on Firebase', function() {
it('updates Firebase', function() {
assert.ok(false, 'Need to confirm that title updates properly');
});
});

describe('addIssueToDatastore updates Firebase as desired', function() {
it('saving works', function () {
assert.ok(false, 'Confirm that adding issues works');
});
});

describe('removeIssueFromDatastore updates Firebase as desired', function() {
it('deleting works', function () {
assert.ok(false, 'Confirm that removing issues works');
});
});

describe('updateIssueInDatastore updates Firebase as desired', function() {
it('updating works', function () {
assert.ok(false, 'Confirm that updating issues works');
});
});
Loading