1 |
|
2 |
|
3 | SlackBot = require '../index'
|
4 | {EventEmitter} = require 'events'
|
5 |
|
6 | {Brain} = require 'brobbot'
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | beforeEach ->
|
12 | @stubs = {}
|
13 | @stubs.channel =
|
14 | name: 'general'
|
15 | id: 'C123'
|
16 | send: (msg) -> msg
|
17 | @stubs.user =
|
18 | name: 'name'
|
19 | id: 'U123'
|
20 | profile:
|
21 | email: 'email@example.com'
|
22 | @stubs.self =
|
23 | name: 'self'
|
24 | id: 'U456'
|
25 | profile:
|
26 | email: 'self@example.com'
|
27 | @stubs.team =
|
28 | name: 'Example Team'
|
29 |
|
30 | @stubs.client =
|
31 | getUserByID: (id) =>
|
32 | for user in @stubs.client.users
|
33 | return user if user.id is id
|
34 | getChannelByID: (id) =>
|
35 | @stubs.channel if @stubs.channel.id == id
|
36 | getChannelGroupOrDMByID: (id) =>
|
37 | @stubs.channel if @stubs.channel.id == id
|
38 | getChannelGroupOrDMByName: (name) =>
|
39 | @stubs.channel if @stubs.channel.name == name
|
40 | users: [@stubs.user, @stubs.self]
|
41 |
|
42 | @stubs.robot = do ->
|
43 | robot = new EventEmitter
|
44 |
|
45 | robot.logger =
|
46 | info: ->
|
47 | debug: ->
|
48 |
|
49 | robot.received = []
|
50 | robot.receive = (msg) ->
|
51 | @received.push msg
|
52 |
|
53 | robot.brain = new Brain robot
|
54 | robot
|
55 |
|
56 |
|
57 | beforeEach ->
|
58 | @slackbot = new SlackBot @stubs.robot
|
59 | @slackbot.client = @stubs.client
|
60 | @slackbot.loggedIn @stubs.self, @stubs.team
|