forked from hubotio/hubot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathes2015_test.js
211 lines (175 loc) · 6.1 KB
/
es2015_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
'use strict'
/* global describe, it */
/* eslint-disable no-unused-expressions */
// Assertions and Stubbing
const chai = require('chai')
const sinon = require('sinon')
chai.use(require('sinon-chai'))
const mockery = require('mockery')
const expect = chai.expect
// Hubot classes
const Hubot = require('../es2015')
const User = Hubot.User
const Brain = Hubot.Brain
const Robot = Hubot.Robot
const Adapter = Hubot.Adapter
const Response = Hubot.Response
const Listener = Hubot.Listener
const TextListener = Hubot.TextListener
const Message = Hubot.Message
const TextMessage = Hubot.TextMessage
const EnterMessage = Hubot.EnterMessage
const LeaveMessage = Hubot.LeaveMessage
const TopicMessage = Hubot.TopicMessage
const JoinMessage = Hubot.JoinMessage
const CatchAllMessage = Hubot.CatchAllMessage
const loadBot = Hubot.loadBot
describe('hubot/es2015', function () {
it('exports User class', function () {
class MyUser extends User {}
const user = new MyUser('id123', { foo: 'bar' })
expect(user).to.be.an.instanceof(User)
expect(user.id).to.equal('id123')
expect(user.foo).to.equal('bar')
})
it('exports Brain class', function () {
class MyBrain extends Brain {}
const robotMock = {
on: sinon.spy()
}
const brain = new MyBrain(robotMock)
expect(brain).to.be.an.instanceof(Brain)
expect(robotMock.on).to.have.been.called
brain.set('foo', 'bar')
expect(brain.get('foo')).to.equal('bar')
})
it('exports Robot class', async function () {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false
})
mockery.registerMock('hubot-mock-adapter', require('./fixtures/mock-adapter.js'))
class MyRobot extends Robot {}
const robot = new MyRobot('mock-adapter', false, 'TestHubot')
await robot.loadAdapter()
expect(robot).to.be.an.instanceof(Robot)
expect(robot.name).to.equal('TestHubot')
mockery.disable()
})
it('exports Adapter class', function () {
class MyAdapter extends Adapter {}
const adapter = new MyAdapter('myrobot')
expect(adapter).to.be.an.instanceof(Adapter)
expect(adapter.robot).to.equal('myrobot')
})
it('exports Response class', function () {
class MyResponse extends Response {}
const robotMock = 'robotMock'
const messageMock = {
room: 'room',
user: 'user'
}
const matchMock = 'matchMock'
const response = new MyResponse(robotMock, messageMock, matchMock)
expect(response).to.be.an.instanceof(Response)
expect(response.message).to.equal(messageMock)
expect(response.match).to.equal(matchMock)
})
it('exports Listener class', function () {
class MyListener extends Listener {}
const robotMock = 'robotMock'
const matcherMock = 'matchMock'
const callback = sinon.spy()
const listener = new MyListener(robotMock, matcherMock, callback)
expect(listener).to.be.an.instanceof(Listener)
expect(listener.robot).to.equal(robotMock)
expect(listener.matcher).to.equal(matcherMock)
expect(listener.options).to.deep.include({
id: null
})
expect(listener.callback).to.equal(callback)
})
it('exports TextListener class', function () {
class MyTextListener extends TextListener {}
const robotMock = 'robotMock'
const regex = /regex/
const callback = sinon.spy()
const textListener = new MyTextListener(robotMock, regex, callback)
expect(textListener).to.be.an.instanceof(TextListener)
expect(textListener.regex).to.equal(regex)
})
it('exports Message class', function () {
class MyMessage extends Message {}
const userMock = {
room: 'room'
}
const message = new MyMessage(userMock)
expect(message).to.be.an.instanceof(Message)
expect(message.user).to.equal(userMock)
})
it('exports TextMessage class', function () {
class MyTextMessage extends TextMessage {}
const userMock = {
room: 'room'
}
const textMessage = new MyTextMessage(userMock, 'bla blah')
expect(textMessage).to.be.an.instanceof(TextMessage)
expect(textMessage).to.be.an.instanceof(Message)
expect(textMessage.text).to.equal('bla blah')
})
it('exports EnterMessage class', function () {
class MyEnterMessage extends EnterMessage {}
const userMock = {
room: 'room'
}
const enterMessage = new MyEnterMessage(userMock)
expect(enterMessage).to.be.an.instanceof(EnterMessage)
expect(enterMessage).to.be.an.instanceof(Message)
})
it('exports LeaveMessage class', function () {
class MyLeaveMessage extends LeaveMessage {}
const userMock = {
room: 'room'
}
const leaveMessage = new MyLeaveMessage(userMock)
expect(leaveMessage).to.be.an.instanceof(LeaveMessage)
expect(leaveMessage).to.be.an.instanceof(Message)
})
it('exports TopicMessage class', function () {
class MyTopicMessage extends TopicMessage {}
const userMock = {
room: 'room'
}
const topicMessage = new MyTopicMessage(userMock)
expect(topicMessage).to.be.an.instanceof(TopicMessage)
expect(topicMessage).to.be.an.instanceof(Message)
})
it('exports JoinMessage class', function () {
class MyJoinMessage extends JoinMessage {}
const userMock = {
room: 'room'
}
const joinMessage = new MyJoinMessage(userMock)
expect(joinMessage).to.be.an.instanceof(JoinMessage)
expect(joinMessage).to.be.an.instanceof(Message)
})
it('exports CatchAllMessage class', function () {
class MyCatchAllMessage extends CatchAllMessage {}
const messageMock = {
user: {
room: 'room'
}
}
const catchAllMessage = new MyCatchAllMessage(messageMock)
expect(catchAllMessage).to.be.an.instanceof(CatchAllMessage)
expect(catchAllMessage).to.be.an.instanceof(Message)
expect(catchAllMessage.message).to.equal(messageMock)
expect(catchAllMessage.user).to.equal(messageMock.user)
})
it('exports loadBot function', function () {
sinon.stub(Hubot, 'Robot')
expect(loadBot).to.be.a('function')
Hubot.loadBot(null, 'adapter', 'enableHttpd', 'botName', 'botAlias')
expect(Hubot.Robot).to.be.called.calledWith(null, 'adapter', 'enableHttpd', 'botName', 'botAlias')
})
})