-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtest-messages.js
More file actions
203 lines (196 loc) · 6.92 KB
/
test-messages.js
File metadata and controls
203 lines (196 loc) · 6.92 KB
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
/**
* Define a common set of test messages along with data on how to set up
* related framework.hears() handlers to validate framework behavior.
*
* @property {string} msgText - message user will send in the test
* @property {string} msgFiles - url to a file to include in message
* @property {int} mentionIndex - 0 index word position where bot mention should be added
* if not set, bot mention is inserted before msgText
* @property {array} hearsInfo - array of objects that describes a
* hears() handler to register for the test
*
* @namespace {object} hearsInfo[]
* Array of object to describe how to register hears() handler. Only phrase is required
* @property {string | regex} phrase - phrase for hears handler
* @property {string} helpstring - help message to register with handler
* @property {integer} priority - priority of hears handler
* @property {string} command - expected value in trigger.command
* @property {string} prompt - expected value in trigger.prompt
*
* All messages defined here will be used in the following tests:
* - bot-created-room-tests.js
* - bot-membership-rules-tests.js
* - guide-mode-rules-tests.jus
* - user-created-room-tests.js
*
* During iterative development is may be helpful to comment out all but one or
* two problematic phrases while running tests
*/
// TODO - Add some hearsInfo phrases that should not match and update the test
// framework to check that the appropriate ones have (or have not) been called
var common = require('../common/common');
module.exports = {
testMessages: [
{
msgText: 'hi',
hearsInfo: [{phrase: 'hi'}]
},
{
msgText: 'Here is a file for ya',
msgFiles: process.env.HOSTED_FILE,
hearsInfo: [{phrase: /.*file.*/im}]
},
{
msgText: 'Here is a whole mess of stuff for ya',
hearsInfo: [{
phrase: /.*/im,
helpString: '',
priority: 99
}]
},
{
msgText: 'Here is a Some Stuff for ya',
hearsInfo: [
{
phrase: /.*Some Stuf.*/im,
helpString: '',
// Will fix multiple different priority tests in subsequent PR
//priority: 2 // lower number == higher priority
},
{
phrase: /.*/im,
helpString: 'This is the catch all',
// Will fix multiple different priority tests in subsequent PR
//priority: 100 // lower number == higher priority
}
]
},
{
msgText: 'echo this is the echo message',
hearsInfo: [
{
phrase: /echo\s/,
command: 'echo ',
prompt: 'this is the echo message',
helpString: '',
// Will fix multiple different priority tests in subsequent PR
// priority: 2 // lower number == higher priority
},
{
phrase: /.*/,
command: 'echo this is the echo message',
prompt: '',
helpString: 'This is the catch all',
// Will fix multiple different priority tests in subsequent PR
//priority: 100 // lower number == higher priority
}
]
},
{
msgText: 'just do it man',
hearsInfo: [
{
phrase: /(^| )do it($| )/i,
command: ' do it ',
prompt: 'man',
helpString: '',
// Will fix multiple different priority tests in subsequent PR
// priority: 2 // lower number == higher priority
},
{
phrase: /.*/,
command: 'just do it man',
prompt: '',
helpString: 'This is the catch all',
// Will fix multiple different priority tests in subsequent PR
//priority: 100 // lower number == higher priority
}
]
},
{
msgText: 'hello. please echo this is the echo message',
// This will result in "hello. please @bot echo this is the echo message"
mentionIndex: 2,
hearsInfo: [
{
phrase: /(^| )echo( |$)/i,
command: ' echo ',
prompt: 'this is the echo message',
helpString: '',
// Will fix multiple different priority tests in subsequent PR
// priority: 2 // lower number == higher priority
},
{
phrase: /.*/,
command: 'hello. please echo this is the echo message',
prompt: '',
helpString: 'This is the catch all',
// Will fix multiple different priority tests in subsequent PR
//priority: 100 // lower number == higher priority
}
]
},
{
msgText: 'hello. please echo this is the echo message',
// This will result in "hello. please echo this is the echo message @bot"
mentionIndex: 7,
hearsInfo: [
{
phrase: /(^| )echo( |$)/i,
command: ' echo ',
prompt: 'this is the echo message',
helpString: '',
// Will fix multiple different priority tests in subsequent PR
// priority: 2 // lower number == higher priority
},
{
phrase: /.*/,
command: 'hello. please echo this is the echo message',
prompt: '',
helpString: 'This is the catch all',
// Will fix multiple different priority tests in subsequent PR
//priority: 100 // lower number == higher priority
}
]
}
],
// External Helper function to iterate through all the user sent msg tests
runUserMessageTests: function(framework, testInfo, testMessages, botShouldRespond=true) {
let behavior = 'should';
if (!botShouldRespond) {
behavior += ' not';
}
testMessages.forEach((testData) => {
let userMsgTest = `user says ${testData.msgText}`;
let botResponseTest = `bot ${behavior} respond to ${testData.msgText}`;
// Don't use ES6 arrow functions to access mocha as this
it(userMsgTest, function() {
testInfo.config.testName = userMsgTest;
if ((testInfo.config?.isDirectTest) && (!common?.botForUser1on1Space)) {
this.skip();
}
return common.userSendMessage(framework, testInfo, testData)
.then((trigger) => {
testInfo.config.priorTestsTrigger = trigger;
});
});
it(botResponseTest, function() {
testInfo.config.testName = botResponseTest;
if ((testInfo.config?.isDirectTest) && (!common?.botForUser1on1Space)) {
this.skip();
}
return common.botRespondsToTrigger(framework,
testInfo, botShouldRespond);
});
it(`clears framework.hears for ${testData.msgText}`, function() {
if ((testInfo.config?.isDirectTest) && (!common?.botForUser1on1Space)) {
this.skip();
}
delete testInfo.config.priorTestsTrigger;
testData.hearsInfo.forEach((info) => {
framework.clearHears(info.functionId);
});
});
});
},
};