UNPKG

1.65 kBtext/coffeescriptView Raw
1# Setup stubs used by the other tests
2
3SlackBot = require '../index'
4{EventEmitter} = require 'events'
5# Use brobbot's brain in our stubs
6{Brain} = require 'brobbot'
7
8# Stub a few interfaces to grease the skids for tests. These are intentionally
9# as minimal as possible and only provide enough to make the tests possible.
10# Stubs are recreated before each test.
11beforeEach ->
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 # Slack client
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 # brobbot.Robot instance
42 @stubs.robot = do ->
43 robot = new EventEmitter
44 # noop the logging
45 robot.logger =
46 info: ->
47 debug: ->
48 # record all received messages
49 robot.received = []
50 robot.receive = (msg) ->
51 @received.push msg
52 # attach a real Brain to the robot
53 robot.brain = new Brain robot
54 robot
55
56# Generate a new slack instance for each test.
57beforeEach ->
58 @slackbot = new SlackBot @stubs.robot
59 @slackbot.client = @stubs.client
60 @slackbot.loggedIn @stubs.self, @stubs.team