Skip to content

Commit

Permalink
some finer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Jul 18, 2016
1 parent df61384 commit 42090fc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
4 changes: 2 additions & 2 deletions scripts/phabs.coffee
Expand Up @@ -67,8 +67,8 @@ module.exports = (robot) ->
name = msg.match[2]
if column?
phab.createTask msg, column, name, (body) ->
if body['error_info']
msg.send "#{body['error_info']}"
if body['result']['error_info']?
msg.send "#{body['result']['error_info']}"
else
id = body['result']['object']['id']
url = process.env.PHABRICATOR_URL + "/T#{id}"
Expand Down
44 changes: 31 additions & 13 deletions test/phabs_test.coffee
Expand Up @@ -156,36 +156,54 @@ describe 'hubot-phabs module', ->


context 'user creates a new task', ->
beforeEach ->
do nock.disableNetConnect
nock(process.env.PHABRICATOR_URL)
.get('/api/user.query')
.reply(200, { result: [ { phid: 'PHID-USER-42' } ] })
.get('/api/maniphest.edit')
.reply(200, { result: { object: { id: 42 } } })

afterEach ->
nock.cleanAll()

context 'phab new something blah blah', ->
hubot 'phab new something blah blah'
it 'fails to comply if the project is not registered by PHABRICATOR_PROJECTS', ->
expect(hubotResponse()).to.eql 'Command incomplete.'

context 'phab new proj1 a task', ->
beforeEach ->
do nock.disableNetConnect
nock(process.env.PHABRICATOR_URL)
.get('/api/user.query')
.reply(200, { result: [ { phid: 'PHID-USER-42' } ] })
.get('/api/maniphest.edit')
.reply(200, { result: { object: { id: 42 } } })

afterEach ->
nock.cleanAll()

context 'when user is doing it for the first time and has no email recorded', ->
hubot 'phab new proj1 a task'
it 'invites the user to set his email address', ->
expect(hubotResponse()).to.eql 'Sorry, I can\'t figure out your email address :( Can you tell me with `.phab me as you@yourdomain.com`?'
context 'when user is doing it for the first time and has set an email addresse', ->
hubot 'phab new proj1 a task', 'user_with_email'
it 'invites the user to set his email address', ->
it 'replies with the object id, and records phid for user', ->
expect(hubotResponse()).to.eql 'Task T42 created = http://example.com/T42'
expect(room.robot.brain.userForId('user_with_email').phid).to.eql 'PHID-USER-42'
context 'when user is known and his phid is in the brain', ->
hubot 'phab new proj1 a task', 'user_with_phid'
it 'invites the user to set his email address', ->
it 'replies with the object id', ->
expect(hubotResponse()).to.eql 'Task T42 created = http://example.com/T42'

context 'phab new proj1 a task', ->
beforeEach ->
do nock.disableNetConnect
nock(process.env.PHABRICATOR_URL)
.get('/api/user.query')
.reply(200, { result: [ { phid: 'PHID-USER-42' } ] })
.get('/api/maniphest.edit')
.reply(200, { result: { error_info: "Something went wrong" } })

afterEach ->
nock.cleanAll()

context 'when something goes wrong on phabricator side', ->
hubot 'phab new proj1 a task', 'user_with_phid'
it 'informs that something went wrong', ->
expect(hubotResponse()).to.eql 'Something went wrong'


context 'user changes status for a task', ->
context 'when the task is unknown', ->
Expand Down

0 comments on commit 42090fc

Please sign in to comment.