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

Testing webhooks and node core labels #60

Merged
merged 6 commits into from
Sep 5, 2016

Conversation

phillipj
Copy link
Member

@phillipj phillipj commented Aug 5, 2016

This is a first shot at testing the code related to webhooks, and node core labelling specifically.

The gist of this is to POST a recorded payload against the bot's /hooks/github endpoint, mock responses from github.com, and verify that the bot tried to GET/POST a set of expected github.com API URLs.

While working on this I noticed a couple of unexpected URLs being requested. Found a bug in the old github npm dependency we used, so decided to update that dependency as well.

Also moved all tests into tests/{integration,unit} directories.

Refs #55

@phillipj phillipj self-assigned this Aug 5, 2016
@phillipj phillipj changed the title WIP: testing webhooks and node core labels Testing webhooks and node core labels Aug 26, 2016
data.action = data.action ? event + '.' + data.action : event

if (!signature || signature !== sign(secret, req.raw)) {
if (!githubSecret.isValid(req)) {

This comment was marked as off-topic.

@phillipj
Copy link
Member Author

@nodejs/github-bot I'm done with this for now, any feedback would be much appreciated ❤️

@Starefossen
Copy link
Member

Had to read up on knock - but from my understanding filesScope.done() and newLabelsScope.done() will throw an exception if the requests have not been called, right?

@phillipj
Copy link
Member Author

.. filesScope.done() and newLabelsScope.done() will throw an exception if the requests have not been called, right?

Yepp, which ends up breaking the tests

@Starefossen
Copy link
Member

Looks solid to me. Will knock throw an exception if there are other requests made which are not intercepted?

@phillipj
Copy link
Member Author

Hm, yeah that would throw, but I'll double check to see if those exceptions are bubbled up correctly making the tests explode

@phillipj
Copy link
Member Author

Found that nock returned error to the request callbacks, which didn't really make the tests explode as badly as I wanted. Just pushed a commit fixing that -- I'll probably make that nock.emitter.on('no match', ..) weirdness a local helper module later.

Includes minor fixes in existing code due to breaking changes in the github dependency.
Previously we adding labels, we actually edited issues with an array of all the labels
the issue should have. That meant we had to include both the pre existing labels, as well
as the labels we resolved by the filepaths changed.

Now with the upgrade of the github npm dependency, we got a new API for *adding new labels*
to issues. That means we don't have to fetch pre existing labels and so forth,
simplifying the process a whole lot.
These changes extracts the logic related to verifying the secret sent
from github.com when webhooks are invoked. Mainly done to enable
turning off the secret verification while running tests.
@phillipj
Copy link
Member Author

@Starefossen what's your preference on commits / squashing? I've tried to separate each set of changes and include a description where needed. Obviously if I squash 'em all it won't be as descriptive in the git log...

@phillipj phillipj merged commit e2bf71b into nodejs:master Sep 5, 2016
@phillipj phillipj deleted the webhooks-testing branch September 5, 2016 18:51
@phillipj
Copy link
Member Author

phillipj commented Sep 5, 2016

Decided to merge this, as it kinda stalled progress on #55. Kept each commit as they're pretty useful on their own, will try to keep the next PRs more focused.

@Starefossen
Copy link
Member

Sorry I dropped the ball on this one @phillipj 😢 I often like to have individual commits in the timeline if they are logical units of work with well written messages instead of squashing them.

@phillipj
Copy link
Member Author

phillipj commented Sep 5, 2016

Sorry I dropped the ball on this one @phillipj 😢

No worries! Seems we agree on commits vs squashing tho :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants