hubot-github-hipchat
Version:
A Hubot-on-hipchat Script for GitHub
89 lines (67 loc) • 2.92 kB
text/coffeescript
chai = require 'chai'
expect = chai.expect
fixtures = require("./fixtures/github-request-fixtures.coffee")
parser = require("../src/notifications/github_payload_parser.coffee")
describe 'Payload Parser', ->
beforeEach ->
= fixtures.stub()
it "should map the repository name to a handy accessor", ->
payload = parser()
expect(payload.repo.name).to.eql(.repository.full_name)
it "should map the repository url to a handy accessor", ->
payload = parser()
expect(payload.repo.url).to.eql(.repository.html_url)
it 'assigns the sender login to who', ->
payload = parser()
expect(payload.who.name).to.eql(.sender.login)
it 'assigns the sender url to who', ->
payload = parser()
expect(payload.who.url).to.eql(.sender.html_url)
context 'which contain a push', ->
beforeEach ->
.action = null
.created = true
.deleted = false
.pusher = {"login": "rob"}
.commits = [1, 2, 3]
.compare = "https://github.com/nedap/banana/compare/123:1234"
.ref = "refs/heads/pamplemousse"
= parser()
it 'gives handy text for how many commits', ->
expect(.push.commit_text).to.eql('3 commits')
it 'maps the ref to a branch name', ->
expect(.push.branch).to.eql('pamplemousse')
it 'maps the compare URL to the url', ->
expect(.push.url).to.eql(.compare)
context 'which contain a pull request', ->
beforeEach ->
.action = 'opened'
.pull_request = fixtures.createPR()
= parser()
it 'maps the pull request title to the pr property', ->
expect(.pr.title).to.eql(.pull_request.title)
it 'maps the pull request number to the pr property', ->
expect(.pr.number).to.eql(.pull_request.number)
context 'which contain an issue (but no comment)', ->
beforeEach ->
.action = 'opened'
.issue = fixtures.createIssue()
= parser()
it 'maps the issue number', ->
expect(.issue.number).to.eql(.issue.number)
it 'maps the issue title', ->
expect(.issue.title).to.eql(.issue.title)
context 'which contain an issue which is a PR', ->
beforeEach ->
.action = 'opened'
.issue = fixtures.createIssue()
.issue.pull_request = fixtures.createIssuePRExtension()
= parser()
it 'knows it is a PR', ->
expect(.pr?).to.be.true
it 'includes the HTML URLs to the PR', ->
expect(.pr.url).to.eql(.issue.pull_request.html_url)
it 'adds the issue title to the PR for convenience', ->
expect(.pr.title).to.eql(.issue.title)
it 'adds the issue number to the PR for convenience', ->
expect(.pr.number).to.eql(.issue.number)