hubot-phabs
Version:
A hubot plugin for communication with a Phabricator instance.
59 lines (52 loc) • 2.12 kB
text/coffeescript
Phabricator = require('../lib/phabricator.coffee')
sinon = require('sinon')
expect = require('chai').use(require('sinon-chai')).expect
nock = require('nock')
describe 'Phabricator lib', ->
context 'when env is not set,', ->
beforeEach ->
delete process.env.PHABRICATOR_URL
delete process.env.PHABRICATOR_API_KEY
delete process.env.PHABRICATOR_BOT_PHID
delete process.env.PHABRICATOR_LISTS_INCOMING
describe '.ready', ->
it 'is false if there is no env set', ->
= new Phabricator null, process.env
msg = sinon.spy()
msg.send = sinon.stub()
ready = .ready(msg)
expect(ready).to.be.false
expect(msg.send).calledTwice
it 'is false if there is no url env set', ->
process.env.PHABRICATOR_URL = 'http://example.com'
= new Phabricator null, process.env
msg = sinon.spy()
msg.send = sinon.stub()
ready = .ready(msg)
expect(msg.send).calledOnce
expect(ready).to.be.false
context 'when env is set,', ->
beforeEach ->
process.env.PHABRICATOR_URL = 'http://example.com'
process.env.PHABRICATOR_API_KEY = 'xxx'
process.env.PHABRICATOR_BOT_PHID = 'PHID-USER-xxx'
process.env.PHABRICATOR_PROJECTS = 'PHID-PROJ-xxx:proj1,PHID-PROJ-yyy:proj2'
= new Phabricator null, process.env
= sinon.spy()
.message = sinon.spy()
.send = sinon.stub()
afterEach ->
delete process.env.PHABRICATOR_URL
delete process.env.PHABRICATOR_API_KEY
delete process.env.PHABRICATOR_BOT_PHID
delete process.env.PHABRICATOR_PROJECTS
describe 'new', ->
it 'should initialize vars', ->
expect(.url).to.eql(process.env.PHABRICATOR_URL)
expect(.apikey).to.eql(process.env.PHABRICATOR_API_KEY)
expect(.bot_phid).to.eql(process.env.PHABRICATOR_BOT_PHID)
describe '.ready', ->
it 'should be ready', ->
ready = .ready()
expect(.send).not.called
expect(ready).to.be.true