AdithyaSK's picture
AdithyaSK HF Staff
Add files using upload-large-folder tool
29fc4be verified
Raw
History Blame Contribute Delete
4.48 kB
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