path = require 'path'
chai = require 'chai'
expect = chai.expect
_ = require 'lodash'
Robot = require 'hubot/src/robot'
Brain = require 'hubot/src/brain'
TextMessage = require('hubot/src/message').TextMessage

process.env.HUBOT_ATTENTION_EVERYONE_LABEL = 'attention-everyone'

describe 'Hubot with attention-everyone script', ->
  beforeEach (done) ->
    @robot = new Robot null, 'mock-adapter', true, 'TestHubot'
    @adapter = @robot.adapter
    @adapter.on 'connected', ->
      @robot.loadFile path.resolve('.', 'src', 'robot-scripts'), 'attention-everyone-handler.coffee'
      @robot.loadFile path.resolve('.', 'src', 'robot-scripts'), 'team-leads.coffee'
    @robot.run()
    @user = @robot.brain.userForId '1',
      name: '@Gary'
      room: '1'
    done()

  afterEach ->
    @robot.server.close()
    @robot.shutdown

  describe 'on review-needed events', ->
    it 'should message Team Leads with PR link', (done) ->
      adapter = @adapter
      robot = @robot
      @robot.receive (new TextMessage @user, 'TestHubot add @Gary as team lead for team 1'), ->
        adapter.on 'reply', (envelope, strings) ->
          expect(strings[0]).to.equal("The attention-everyone label was added to PR(2) https://github.com/a/b/pull/2\nAll Team Leads need to review this Pull Request")
          done()
        json = _.cloneDeep(require '../../fixtures/label-added')
        json.label.name = 'attention-everyone'
        robot.emit 'github.pull_request.labeled', json
