-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebexBotTests.postman_collection.json
644 lines (644 loc) · 22.9 KB
/
WebexBotTests.postman_collection.json
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
{
"info": {
"_postman_id": "53ae6d85-2040-4ca8-99e9-a0c209685b88",
"name": "webex-bot Tests",
"description": "This is a set of test input designed to test and validate the expected behavior of the webex-bot which is included as part of the bot-test-framework-example (https://github.com/jpjpjp/bot-test-framework-example). These tests can be run when the Webex API Emulator and the webex-bot are running as described in the readme of that project.\n\nThe following environment variables must be set prior to running the tests\nAPI_URL -- the url where the webex api emulator is running, ie http://localhost:3210\nWEBEX_TOKEN -- a token specified in tokens.json for the webex api emulator\nbot_email -- the email ID of the bot that will be tested. Specified in tokens.json\nbot_id -- the id of the bot being tested. Specified in tokens.json\ntester_name -- the name of the user running the tests. Specified in tokens.json\ntester_email -- the email of the user running the tests. Specified in tokens.json\n\nEach test emulates some type of user input to Webex Teams API. It is sent to the emulator endpoint specified in the API_URL environment variable.\n\nWhen we expect the webex-bot to respond with some request(s), we specify the X-Bot-Responses header to the number of requests we expect the bot to send. The Emulator will intercept the \"normal\" responses to our test cases and collect the bot responses, adding them to our response before sending the response back to Postman.\n\nEach Test case can then examine the responses for both the expected response to our initial test request and for the expected bot responses that would follow it.\n\nNote that the first request in the collection includes some globally defined tests that are evaluated in subsequent tests so the tests must be run in order.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Create a group room (and define global test cases)",
"event": [
{
"listen": "test",
"script": {
"id": "75bfb49c-1bca-4eb8-a234-bf2b36aae844",
"type": "text/javascript",
"exec": [
"// Save common tests in a global variable",
"// Check if the initial test request returned the expected value",
"postman.setGlobalVariable(\"commonTests\", (task, status) => {",
" // We expect a 200 OK",
" tests[task + \" returned \" + status] = responseCode.code === status;",
" // The Content-Type must be JSON",
" tests[\"Content-Type header is set\"] = postman.getResponseHeader(\"Content-Type\") === \"application/json;charset=UTF-8\";",
"});",
"",
"// When X-Bot-Responses header is set, check to see if we got an expected",
"// consolidated response body",
"postman.setGlobalVariable(\"bodyIncludesBotResponsesTest\", () => {",
" // The response body includes both the response plus the expected bot requests",
" var data = JSON.parse(responseBody);",
" var expectedResponses = request.headers['x-bot-responses'];",
" tests[\"X-Bot-Responses request header was set to:\" + expectedResponses] = expectedResponses !== undefined;",
" tests[\"Response body has a TestFrameworkResponse object\"] = data.testFrameworkResponse !== undefined;",
" tests[\"Response body has the botResponses array\"] = data.botResponses !== undefined;",
"});",
"",
"// Check if the bot sent us an expected message in text format",
"postman.setGlobalVariable(\"botResponseMessageText\", (botResponse, roomId, message) => {",
" tests[\"Bot called the /messages API\"] = botResponse.route === '/messages';",
" tests[\"Bot message was sent to room ID: \"+roomId] = botResponse.body.roomId === roomId;",
" tests[\"Bot sent expected text: \"+message] = botResponse.body.text === message;",
"});",
"",
"// Check if the bot sent us an expected message in markdown format",
"postman.setGlobalVariable(\"botResponseMessageMarkdown\", (botResponse, roomId, message) => {",
" tests[\"Bot called the /messages API\"] = botResponse.route === '/messages';",
" tests[\"Bot message was sent to room ID: \"+roomId] = botResponse.body.roomId === roomId;",
" tests[\"Bot sent expected markdown: \"+message] = botResponse.body.markdown === message;",
"});",
"",
"",
"// Run the common tests for the create room request",
"eval(globals.commonTests)(\"Create room\", 200);",
"",
"// We don't expect any responses from the bot for this call",
"",
"// Assuming all went well get the room id ",
"var jsonData = JSON.parse(responseBody);",
"if (jsonData.id === undefined) {",
" tests[\"Create a room: cannot retreive room identifier\"] = false",
"}",
"else {",
" var roomID = jsonData.id;",
" postman.setEnvironmentVariable(\"_room\", roomID);",
" tests[\"Create a room: created with id:\" + roomID] = true",
"}",
"",
""
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{webex_token}}"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "",
"value": "",
"disabled": true
}
],
"body": {
"mode": "raw",
"raw": "{\n \"title\": \"Bot-Tester-Room\"\n}"
},
"url": {
"raw": "{{API_URL}}/rooms",
"host": [
"{{API_URL}}"
],
"path": [
"rooms"
]
},
"description": "Creates a room. The authenticated user is automatically added as a member of the room. \n\nThe bot is not in the room at this point so we don not expect any bot responses.\n\nOn the test tab we define some global tests methods that will be used in subseqent test cases.\n\nIn addition we capture the roomId of the created room and store it in the _roomId environment variable for us in subseqent requests."
},
"response": []
},
{
"name": "Add bot to group room",
"event": [
{
"listen": "test",
"script": {
"id": "1ae78f95-f9c8-4e56-ab1f-349395f24d1c",
"type": "text/javascript",
"exec": [
"// First, run the common tests",
"eval(globals.commonTests)(\"Add Bot to room\", 200);",
"// No bot responses expected so we are done"
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{webex_token}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n\t\"roomId\": \"{{_room}}\",\r\n\t\"personId\": \"{{bot_id}}\",\r\n \"isModerator\": false\r\n}"
},
"url": {
"raw": "{{API_URL}}/memberships",
"host": [
"{{API_URL}}"
],
"path": [
"memberships"
]
},
"description": "Adds the bot to the previously created room. Note that the bot is added via the personId element in the body. The Webex API emulator does not fully support referring to users via email yet.\n\nThe bot's person id should be specified in the bot_id environment variable.\n\nNo bot response is expected to this test."
},
"response": []
},
{
"name": "List memberships (2)",
"event": [
{
"listen": "test",
"script": {
"id": "90062892-27d4-4dec-a0a9-ef23eb72bd5c",
"type": "text/javascript",
"exec": [
"// First, run the common tests",
"eval(globals.commonTests)(\"List the memberships for the room\", 200);",
"",
"// Assuming all went well confirm the expected two memeberships",
"var jsonData = JSON.parse(responseBody);",
"if (jsonData.items === undefined) {",
" tests[\"Memberships: cannot retreive membership info\"] = false",
"}",
"else {",
" var count = jsonData.items.length;",
" if (count != 2) {",
" var testStr = \"Membership Count: Exepected 2 memberships, got %d\", count;",
" tests[testStr] = false",
" } else {",
" tests[\"Membership Count: Got the exepected 2 memberships\"] = true;",
" }",
"}",
""
]
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "Bearer {{webex_token}}"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{API_URL}}/memberships?roomId={{_room}}",
"host": [
"{{API_URL}}"
],
"path": [
"memberships"
],
"query": [
{
"key": "roomId",
"value": "{{_room}}"
}
]
},
"description": "Lists memberships for the room. Validate that there are two users in the room, the testing user (Mr. Postman) and the bot (Bot).\n\nNo bot responses are expected after making this request.\n"
},
"response": []
},
{
"name": "Send /hello message to space",
"event": [
{
"listen": "test",
"script": {
"id": "25a31ead-417a-48de-864e-2be6077cbe2a",
"type": "text/javascript",
"exec": [
"// First, run the common tests",
"eval(globals.commonTests)(\"Send help message to the bot\", 200);",
"",
"// Check that we got the combined webex API and bot response payload",
"eval(globals.bodyIncludesBotResponsesTest)()",
"",
"// Check if we got the expected message from the bot",
"",
"var jsonData = JSON.parse(responseBody);",
"var testFrameworkResponse = jsonData.testFrameworkResponse;",
"var botResponses = jsonData.botResponses;",
"",
"var roomId = postman.getEnvironmentVariable(\"_room\");",
"var expectedResponses = request.headers['x-bot-responses'];",
"if (botResponses.length == expectedResponses) {",
" tests[\"Bot responded with \" + expectedResponses + \" requests:\"] = true;",
" var botResponse = jsonData.botResponses[0]",
" var testerName = postman.getEnvironmentVariable(\"tester_name\");",
" var resultMsg = testerName + ', you said hello to me!';",
" eval(globals.botResponseMessageText)(botResponse, roomId, resultMsg);",
"} else {",
" tests[\"Bot responded with \" + expectedResponses + \" requests:\"] = false;",
"}",
"",
" ",
" ",
""
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{webex_token}}"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "X-Bot-Responses",
"value": "1"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"roomId\" : \"{{_room}}\",\r\n \"markdown\" : \"<@personId:{{bot_id}}|Bot> /hello\"\r\n}"
},
"url": {
"raw": "{{API_URL}}/messages",
"host": [
"{{API_URL}}"
],
"path": [
"messages"
]
},
"description": "Post a message to the space that mentions the bot and includes the command /hello\n\nThe @mention is accomplished by using the bot's id as the emulator does not yet fully handle referring to users via email or name.\n\nWe do expect the bot to send one request in response to this request so we set the X-Bot-Response header to 1.\n\nThe tests will inspect the consolidated response body to ensure that our request was handled properly and that the bot replied with the expected message, ie \"Hello Mr. Postman\"."
},
"response": []
},
{
"name": "Send /whoami message to the space",
"event": [
{
"listen": "test",
"script": {
"id": "27165e43-76ac-4208-b5c6-ca6cbc735270",
"type": "text/javascript",
"exec": [
"// First, run the common tests",
"eval(globals.commonTests)(\"Send help message to the bot\", 200);",
"",
"// Check that we got the combined webex API and bot response payload",
"eval(globals.bodyIncludesBotResponsesTest)()",
"var jsonData = JSON.parse(responseBody);",
"var testFrameworkResponse = jsonData.testFrameworkResponse;",
"var botResponses = jsonData.botResponses;",
"",
"// Check that we got the expected bot responses",
"var roomId = postman.getEnvironmentVariable(\"_room\");",
"var expectedResponses = request.headers['x-bot-responses'];",
"if (botResponses.length == expectedResponses) {",
" tests[\"Bot responded with \" + expectedResponses + \" requests:\"] = true;",
" var botResponse = jsonData.botResponses[0];",
" // Check if we got the expected first message from the bot",
" var testerName = postman.getEnvironmentVariable(\"tester_name\");",
" var resultMsg = testerName + ' here is some of your information: \\n\\n\\n **Room:** you are in \\\"**Bot-Tester-Room**\\\" \\n\\n\\n **Room id:** *' + roomId + '*';",
" eval(globals.botResponseMessageMarkdown)(botResponse, roomId, resultMsg);",
" ",
" // Check if we got the expected seconde message from the bot",
" botResponse = jsonData.botResponses[1];",
" var testerEmail = postman.getEnvironmentVariable(\"tester_email\");",
" resultMsg = ' **Email:** your email on file is *' + testerEmail + '*';",
" eval(globals.botResponseMessageMarkdown)(botResponse, roomId, resultMsg);",
"} else {",
" tests[\"Bot responded with \" + expectedResponses + \" requests:\"] = false;",
"}",
"",
" ",
" ",
""
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{webex_token}}"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "X-Bot-Responses",
"value": "2"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"roomId\" : \"{{_room}}\",\r\n \"markdown\" : \"<@personId:{{bot_id}}|Bot> /whoami\"\r\n}"
},
"url": {
"raw": "{{API_URL}}/messages",
"host": [
"{{API_URL}}"
],
"path": [
"messages"
]
},
"description": "Post a message to the space that mentions the bot and includes the command /whoami\n\nThe @mention is accomplished by using the bot's id as the emulator does not yet fully handle referring to users via email or name.\n\nWe do expect the bot to send two requests in response to this request so we set the X-Bot-Response header to 2.\n\nThe tests will inspect the consolidated response body to ensure that our request was handled properly and that the bot replied with the expected message. In this case we expect the bot to reply with two markdown messages."
},
"response": []
},
{
"name": "Send /echo message to space",
"event": [
{
"listen": "test",
"script": {
"id": "628bfa6b-b0d8-4193-9dbe-9acaea5a4f12",
"type": "text/javascript",
"exec": [
"// First, run the common tests",
"eval(globals.commonTests)(\"Send help message to the bot\", 200);",
"",
"// Check that we got the combined webex API and bot response payload",
"eval(globals.bodyIncludesBotResponsesTest)()",
"",
"// Check that we got the expected bot response",
"var jsonData = JSON.parse(responseBody);",
"var testFrameworkResponse = jsonData.testFrameworkResponse;",
"var botResponses = jsonData.botResponses;",
"",
"var roomId = postman.getEnvironmentVariable(\"_room\");",
"var expectedResponses = request.headers['x-bot-responses'];",
"if (botResponses.length == expectedResponses) {",
" tests[\"Bot responded with \" + expectedResponses + \" requests:\"] = true;",
" var botResponse = jsonData.botResponses[0]",
" // Check if we got the expected message from the bot",
" eval(globals.botResponseMessageText)(botResponse, roomId, \"Ok, I'll say it: \\\"Repeat this back to me.\\\"\");",
"} else {",
" tests[\"Bot responded with \" + expectedResponses + \" requests:\"] = false;",
"}",
"",
" ",
" ",
""
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{webex_token}}"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "X-Bot-Responses",
"value": "1"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"roomId\" : \"{{_room}}\",\r\n \"markdown\" : \"<@personId:{{bot_id}}|Bot> /echo Repeat this back to me.\"\r\n}"
},
"url": {
"raw": "{{API_URL}}/messages",
"host": [
"{{API_URL}}"
],
"path": [
"messages"
]
},
"description": "Post a message to the space that mentions the bot and includes the command /echo\n\nThe @mention is accomplished by using the bot's id as the emulator does not yet fully handle referring to users via email or name.\n\nWe expect the bot to send one request in response to this request so we set the X-Bot-Response header to 1.\n\nThe tests will inspect the consolidated response body to ensure that our request was handled properly and that the bot replied with the expected message in text format."
},
"response": []
},
{
"name": "Send /leave message to space",
"event": [
{
"listen": "test",
"script": {
"id": "9d3370da-2cd8-4956-9157-e6adcc2571a0",
"type": "text/javascript",
"exec": [
"// First, run the common tests",
"eval(globals.commonTests)(\"Send help message to the bot\", 200);",
"",
"// Check that we got the combined webex API and bot response payload",
"eval(globals.bodyIncludesBotResponsesTest)()",
"var jsonData = JSON.parse(responseBody);",
"var testFrameworkResponse = jsonData.testFrameworkResponse;",
"var botResponses = jsonData.botResponses;",
"",
"",
"// Check that we got the expected bot responses",
"var roomId = postman.getEnvironmentVariable(\"_room\");",
"var expectedResponses = request.headers['x-bot-responses'];",
"if (botResponses.length == expectedResponses) {",
" tests[\"Bot responded with \" + expectedResponses + \" requests:\"] = true;",
" var botResponse = jsonData.botResponses[0];",
" // Check if we got the expected message from the bot",
" eval(globals.botResponseMessageText)(botResponse, roomId, \"OK. I know when I'm not wanted...\");",
" // Check if the bot left the space",
" botResponse = jsonData.botResponses[1];",
" tests[\"Bot deleted a membership\"] = botResponse.method === 'DELETE';",
"} else {",
" tests[\"Bot responded with \" + expectedResponses + \" requests:\"] = false;",
"}",
"",
" ",
" ",
""
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{webex_token}}"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "X-Bot-Responses",
"value": "2"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"roomId\" : \"{{_room}}\",\r\n \"markdown\" : \"<@personId:{{bot_id}}|Bot> /leave\"\r\n}"
},
"url": {
"raw": "{{API_URL}}/messages",
"host": [
"{{API_URL}}"
],
"path": [
"messages"
]
},
"description": "Post a message to the space that mentions the bot and includes the command /leave\n\nThe @mention is accomplished by using the bot's id as the emulator does not yet fully handle referring to users via email or name.\n\nWe expect the bot to send two requests in response to this request so we set the X-Bot-Response header to 2.\n\nThe tests will inspect the consolidated response body to ensure that our request was handled properly and that the bot replied with a text format message and then deleted it's membership in the room."
},
"response": []
},
{
"name": "List memberships (1)",
"event": [
{
"listen": "test",
"script": {
"id": "f01919fd-d05d-44bd-962b-a5ae82f6b38d",
"type": "text/javascript",
"exec": [
"// First, run the common tests",
"eval(globals.commonTests)(\"List the memberships for the room\", 200);",
"",
"// Assuming all went well confirm the expected one memebership",
"var jsonData = JSON.parse(responseBody);",
"if (jsonData.items === undefined) {",
" tests[\"Memberships: cannot retreive membership info\"] = false",
"}",
"else {",
" var count = jsonData.items.length;",
" if (count != 1) {",
" var testStr = \"Membership Count: Exepected 1 membership1, got %d\", count;",
" tests[testStr] = false",
" } else {",
" tests[\"Membership Count: Got the exepected 1 membership\"] = true;",
" }",
"}"
]
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "Bearer {{webex_token}}"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{API_URL}}/memberships?roomId={{_room}}",
"host": [
"{{API_URL}}"
],
"path": [
"memberships"
],
"query": [
{
"key": "roomId",
"value": "{{_room}}"
}
]
},
"description": "Lists memberships in the room.\n\nWe do not expect a bot response in this case. This is more of a classic test, where we simply confirm that the number of memberships in the room is back down to one since the bot left."
},
"response": []
},
{
"name": "Delete group room",
"event": [
{
"listen": "test",
"script": {
"id": "52416ba1-bb5f-4969-932a-2d0461b2a2a1",
"type": "text/javascript",
"exec": [
"if (responseCode.code != 204) {",
" tests[\"Delete a room: failed\"] = false",
"}",
"else {",
" tests[\"Delete a room: success\"] = true",
"}"
]
}
}
],
"request": {
"method": "DELETE",
"header": [
{
"key": "Authorization",
"value": "Bearer {{webex_token}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{API_URL}}/rooms/{{_room}}",
"host": [
"{{API_URL}}"
],
"path": [
"rooms",
"{{_room}}"
]
},
"description": "Deletes the space that we have been working in.\r\n\r\n"
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"id": "771c1c1d-eb4d-4fb1-93b9-d90b0e61f366",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "aca1ae9b-145c-4b65-96a2-0f64fe1c1968",
"type": "text/javascript",
"exec": [
""
]
}
}
]
}