'use strict'

/* global describe, beforeEach, afterEach, it */

const Helper = require('hubot-test-helper')
const chai = require('chai')

const helper = new Helper('../src/<%= scriptName %>')

const expect = chai.expect

describe('<%= scriptName %>', () => {
  let room

  beforeEach(() => {
    room = helper.createRoom()
  })

  afterEach(() => {
    room.destroy()
  })

  it('responds to hello', () => {
    room.user.say('alice', '@hubot hello').then(() => {
      expect(room.messages).to.eql([
        ['alice', '@hubot hello'],
        ['hubot', '@alice hello!']
      ])
    })
  })

  it('hears orly', () => {
    room.user.say('bob', 'just wanted to say orly').then(() => {
      expect(room.messages).to.eql([
        ['bob', 'just wanted to say orly'],
        ['hubot', 'yarly']
      ])
    })
  })
})

@@ -63,22 +63,20 @@
 %0A%0Aconst 
-Helper
+path
  = requi
@@ -83,28 +83,16 @@
 re('
-hubot-test-helper
+path
 ')%0A
+%0A
 cons
@@ -120,90 +120,308 @@
 i')%0A
-%0Aconst helper = new Helper('../src/%3C%25= scriptName %25%3E')%0A%0Aconst expect = chai.expect
+const Hubot = require('hubot')%0A%0Aconst expect = chai.expect%0Aconst Robot = Hubot.Robot%0Aconst TextMessage = Hubot.TextMessage%0A%0Achai.use(require('sinon-chai'))%0A%0Adescribe('require(%22%3C%25= scriptName %25%3E%22)', () =%3E %7B%0A  it('exports a function', () =%3E %7B%0A    expect(require('../index')).to.be.a('Function')%0A  %7D)%0A%7D)
 %0A%0Ade
@@ -464,18 +464,25 @@
   let ro
-om
+bot, user
 %0A%0A  befo
@@ -506,31 +506,355 @@
   ro
-om = helper.createRoom(
+bot = new Robot(null, 'mock-adapter-v3', false, 'hubot')%0A    robot.loadFile(path.resolve('src/'), '%3C%25= scriptName %25%3E.js')%0A    robot.adapter.on('connected', () =%3E %7B%0A      robot.brain.userForId('1', %7B%0A        name: 'john',%0A        real_name: 'John Doe',%0A        room: '#test'%0A      %7D)%0A    %7D)%0A    robot.run()%0A    user = robot.brain.userForName('john'
 )%0A  
@@ -887,18 +887,20 @@
   ro
-om.destroy
+bot.shutdown
 ()%0A 
@@ -927,24 +927,28 @@
 to hello', (
+done
 ) =%3E %7B%0A    r
@@ -952,179 +952,218 @@
   ro
-om.user.say('alice', '@hubot hello').then(() =%3E %7B%0A      expect(room.messages).to.eql(%5B%0A        %5B'alice', '@hubot hello'%5D,%0A        %5B'hubot', '@alice hello!'%5D%0A      %5D)%0A    %7D
+bot.adapter.on('reply', function (envelope, strings) %7B%0A      const answer = strings%5B0%5D%0A%0A      expect(answer).to.eql('hello!')%0A%0A      done()%0A    %7D)%0A%0A    robot.adapter.receive(new TextMessage(user, 'hubot hello')
 )%0A  
@@ -1182,24 +1182,28 @@
 ars orly', (
+done
 ) =%3E %7B%0A    r
@@ -1207,189 +1207,228 @@
   ro
-om.user.say('bob', 'just wanted to say orly').then(() =%3E %7B%0A      expect(room.messages).to.eql(%5B%0A        %5B'bob', 'just wanted to say orly'%5D,%0A        %5B'hubot', 'yarly'%5D%0A      %5D)%0A    %7D
+bot.adapter.on('send', function (envelope, strings) %7B%0A      const answer = strings%5B0%5D%0A%0A      expect(answer).to.eql('yarly')%0A%0A      done()%0A    %7D)%0A%0A    robot.adapter.receive(new TextMessage(user, 'just wanted to say orly')
 )%0A  

remove hubot-test-helper