-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathguided-mode-rules-tests.js
More file actions
132 lines (113 loc) · 5.17 KB
/
guided-mode-rules-tests.js
File metadata and controls
132 lines (113 loc) · 5.17 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
// Variables an functions shared by all tests
var common = require('../common/common');
let tm = require('../common/test-messages');
let btm = require('../common/bot-test-messages');
let framework = common.framework;
let testInfo = common.testInfo;
let disallowedUser = common.getDisallowedUser();
let User_Test_Space_Title = common.User_Test_Space_Title;
let validator = common.validator;
let paramCombos = [
{},
{'membershipRulesDisallowedResponse': ''},
{'membershipRulesDisallowedResponse': '',
'membershipRulesStateMessageResponse': ''},
{'membershipRulesDisallowedResponse': '',
'membershipRulesStateMessageResponse': '',
'membershipRulesAllowedResponse': ''},
{'membershipRulesDisallowedResponse': 'No guides in this space, so I ain\'t working',
'membershipRulesStateMessageResponse': 'Can\'t answer ya pal. No guides in this space',
'membershipRulesAllowedResponse': 'Yay, there is a guide here. I can work now!'}
];
paramCombos.forEach(function(paramCombo, testIndex) {
describe(`Non Guide Creates Room with Bot for test ${testIndex + 1}`, () => {
// Set the framework guide mode bot response params for this test
before(() => {
Object.entries(paramCombo).forEach(([key, value]) => {
framework[key] = value;
});
console.log(` Test ${testIndex + 1} runs with the following guide mode config:`);
if (framework.membershipRulesDisallowedResponse) {
console.log(` - When bot is added to a space with no guides, framework responds with "${framework.membershipRulesDisallowedResponse}"`);
} else {
console.log(' - Framework will not respond when bot is added to a space with no guides');
}
if (framework.membershipRulesStateMessageResponse) {
console.log(` - When bot is mentioned in a space with no guides, framework responds with "${framework.membershipRulesStateMessageResponse}"`);
} else {
console.log(' - Framework will not respond when bot mentioned in a space with no guides');
}
if (framework.membershipRulesAllowedResponse) {
console.log(` - When a guide enters a previously unguided space, framework will respond with "${framework.membershipRulesAllowedResponse}"`);
} else {
console.log(' - Framework will not respond when a guide enters a previously unguided space');
}
});
// Create a room as user to have test bot which will create other rooms
before(() => disallowedUser.rooms.create({title: User_Test_Space_Title})
.then((r) => {
testInfo.config.roomUnderTest = r;
testInfo.config.userUnderTest = disallowedUser;
return validator.isRoom(r);
}));
// Add our bot to the room and validate that no spawn event occurs
// since our bot should not work in when added to a space without a guide
before(() => {
testInfo.config.testName = 'Disallowed User Adds Bot to Space';
return common.addBotToSpace(framework, testInfo, /*shouldFail = */ true)
.then((b) => {
testInfo.config.botUnderTest = b;
});
});
// Bot leaves rooms
after(() => {
//TODO add code to validate that testInfo.config.botUnderTest is set.
testInfo.config.testName = 'Bot Leaves Space';
return common.botLeaveSpace(framework, testInfo);
});
// User deletes room -- cleanup
after(() => {
delete testInfo.config.botUnderTest;
return disallowedUser.rooms.remove(testInfo.config.roomUnderTest)
.catch((reason) => {
console.error('Failed to cleanup test room', reason);
throw reason;
});
});
describe('User sends message and bot should not respond', () => {
// loop through user message tests..
tm.runUserMessageTests(framework, testInfo, tm.testMessages,
/* botShouldRespond = */false);
});
describe('disabled bot attempts sends messages', () => {
// loop through bot message tests..
btm.runBotMessageTests(framework, testInfo, btm.botTestMessages,
/* shouldFail = */true);
});
describe('Bot adds guide user to space and iteracts with bot', () => {
before(() => {
testInfo.config.testName = 'bot adds a guide user to the room';
return common.botAddUsersToSpace(framework, testInfo,
[common.userPerson.emails[0]]);
});
describe('User sends message and bot should respond', () => {
// loop through user message tests..
tm.runUserMessageTests(framework, testInfo, tm.testMessages,
/* botShouldRespond = */true);
});
});
describe('Bot removes guide user from space and other user iteracts with it', () => {
before(() => {
testInfo.config.testName = 'removes guide user from the room';
return common.botRemoveUserFromSpace(framework, testInfo,
common.userPerson.emails[0], 1, /* numDisallowedUsersInSpace */
false, /* isDisallowedUser */);
});
describe('User sends message and bot should no longer respond', () => {
// loop through user message tests..
tm.runUserMessageTests(framework, testInfo, tm.testMessages,
/* botShouldRespond = */false);
});
});
});
});