File size: 4,481 Bytes
29fc4be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
diff --git a/test/BootBot.spec.js b/test/BootBot.spec.js
index 39f0157..68df63c 100644
--- a/test/BootBot.spec.js
+++ b/test/BootBot.spec.js
@@ -116,6 +116,93 @@ describe('BootBot', () => {
     expect(spy.calledWith(expected)).to.equal(true);
   });
 
+  it('formats a string quick reply with default content_type, title, and payload', () => {
+    const spy = sinon.spy(bot, 'sendRequest');
+    bot.sendTextMessage(userId, 'Hello', ['Red']);
+    const body = spy.firstCall.args[0];
+    expect(body.message.quick_replies).to.deep.equal([
+      { content_type: 'text', title: 'Red', payload: 'BOOTBOT_QR_RED' }
+    ]);
+  });
+
+  it('passes through a location quick reply object as-is', () => {
+    const spy = sinon.spy(bot, 'sendRequest');
+    bot.sendTextMessage(userId, 'Where are you?', [{ content_type: 'location' }]);
+    const body = spy.firstCall.args[0];
+    expect(body.message.quick_replies).to.deep.equal([
+      { content_type: 'location' }
+    ]);
+  });
+
+  it('preserves all fields of a text quick reply with image_url', () => {
+    const spy = sinon.spy(bot, 'sendRequest');
+    const reply = {
+      content_type: 'text',
+      title: 'Green',
+      payload: 'DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_GREEN',
+      image_url: 'http://petersfantastichats.com/img/green.png'
+    };
+    bot.sendTextMessage(userId, 'Pick a color', [reply]);
+    const body = spy.firstCall.args[0];
+    expect(body.message.quick_replies).to.deep.equal([reply]);
+  });
+
+  it('auto-generates payload and content_type for an object with only a title', () => {
+    const spy = sinon.spy(bot, 'sendRequest');
+    bot.sendTextMessage(userId, 'Pick', [{ title: 'Red' }]);
+    const body = spy.firstCall.args[0];
+    expect(body.message.quick_replies).to.deep.equal([
+      { content_type: 'text', title: 'Red', payload: 'BOOTBOT_QR_RED' }
+    ]);
+  });
+
+  it('preserves user-provided payload when title is supplied', () => {
+    const spy = sinon.spy(bot, 'sendRequest');
+    bot.sendTextMessage(userId, 'Pick', [{ title: 'Red', payload: 'CUSTOM_RED_PAYLOAD' }]);
+    const body = spy.firstCall.args[0];
+    const qr = body.message.quick_replies[0];
+    expect(qr.title).to.equal('Red');
+    expect(qr.payload).to.equal('CUSTOM_RED_PAYLOAD');
+    expect(qr.content_type).to.equal('text');
+  });
+
+  it('formats a mixed array of string and object quick replies correctly', () => {
+    const spy = sinon.spy(bot, 'sendRequest');
+    bot.sendTextMessage(userId, 'Pick', [
+      'Red',
+      { content_type: 'location' },
+      { content_type: 'text', title: 'Blue', payload: 'PICK_BLUE', image_url: 'http://x/blue.png' }
+    ]);
+    const body = spy.firstCall.args[0];
+    expect(body.message.quick_replies).to.deep.equal([
+      { content_type: 'text', title: 'Red', payload: 'BOOTBOT_QR_RED' },
+      { content_type: 'location' },
+      { content_type: 'text', title: 'Blue', payload: 'PICK_BLUE', image_url: 'http://x/blue.png' }
+    ]);
+  });
+
+  it('preserves extra fields on a location quick reply', () => {
+    const spy = sinon.spy(bot, 'sendRequest');
+    bot.sendTextMessage(userId, 'Where?', [{ content_type: 'location', extra_field: 'KEEP_ME' }]);
+    const body = spy.firstCall.args[0];
+    const qr = body.message.quick_replies[0];
+    expect(qr.content_type).to.equal('location');
+    expect(qr.extra_field).to.equal('KEEP_ME');
+  });
+
+  it('formats quick replies on sendAttachment the same way as sendTextMessage', () => {
+    const spy = sinon.spy(bot, 'sendRequest');
+    bot.sendAttachment(userId, 'image', 'http://x/img.png', [
+      { content_type: 'location' },
+      { title: 'Red' }
+    ]);
+    const body = spy.firstCall.args[0];
+    expect(body.message.quick_replies).to.deep.equal([
+      { content_type: 'location' },
+      { content_type: 'text', title: 'Red', payload: 'BOOTBOT_QR_RED' }
+    ]);
+  });
+
   it('can send an attachment', () => {
     const spy = sinon.spy(bot, 'sendRequest');
     const type = 'image';
diff --git a/test_commands.json b/test_commands.json
new file mode 100644
index 0000000..fdb8120
--- /dev/null
+++ b/test_commands.json
@@ -0,0 +1,3 @@
+{
+  "test_commands": ["npx mocha test/BootBot.spec.js"]
+}
diff --git a/mimo_test_command.sh b/mimo_test_command.sh
new file mode 100755
--- /dev/null
+++ b/mimo_test_command.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+set -uo pipefail
+cd /testbed
+rc=0
+npx mocha test/BootBot.spec.js
+rc=$(( rc | $? ))
+exit $rc