Skip to content

Commit

Permalink
fixed tests and few issues
Browse files Browse the repository at this point in the history
  • Loading branch information
miki2826 committed Sep 13, 2016
1 parent 5269134 commit c5a166e
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ botly.getUserProfile(accountLinkingToken, function (err, info) {
});
```

#### createWebURLButton (title, url[, heightRatio][, supportExtention][, fallbackURL])
#### createWebURLButton (title, url[, heightRatio][, supportExtension][, fallbackURL])

#### createAccountLinkButton (url)

Expand Down
27 changes: 18 additions & 9 deletions lib/Botly.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ Botly.prototype.setWhiteList = function (options, callback) {
access_token: this.accessToken || options.accessToken
},
body: {
setting_type : 'domain_whitelisting',
whitelisted_domains : options.whiteList,
setting_type: 'domain_whitelisting',
whitelisted_domains: options.whiteList,
domain_action_type: options.actionType || 'add'
}

Expand Down Expand Up @@ -272,8 +272,10 @@ Botly.prototype.sendAttachment = function (options, callback) {
Botly.prototype.sendImage = function (options, callback) {
options.payload = options.payload || {
url: options.url,
is_reusable: options.is_reusable || false
};
if (options.is_reusable) {
options.payload.is_reusable = options.is_reusable;
}
options.type = ATTACHMENT_TYPE.IMAGE;
this.sendAttachment(options, callback);
};
Expand Down Expand Up @@ -306,15 +308,22 @@ Botly.prototype.sendReceipt = function (options, callback) {
this.sendAttachment(options, callback);
};

Botly.prototype.createWebURLButton = function (title, url, heightRatio, supportExtention, fallbackURL) {
return {
Botly.prototype.createWebURLButton = function (title, url, heightRatio, supportExtension, fallbackURL) {
let button = {
type: BUTTON_TYPE.WEB_URL,
title: title,
url: url,
webview_height_ratio: heightRatio || WEBVIEW_HEIGHT_RATIO.FULL,
messenger_extensions: supportExtention || false,
fallback_url: fallbackURL || url
url: url
};
if (heightRatio) {
button.webview_height_ratio = heightRatio;
}
if (supportExtension) {
button.messenger_extensions = supportExtension;
}
if (fallbackURL) {
button.fallback_url = fallbackURL;
}
return button;
};

Botly.prototype.createAccountLinkButton = function (url) {
Expand Down
96 changes: 90 additions & 6 deletions test/botly_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ describe('Botly Tests', function () {
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH
});

botly.sendText({id: USER_ID, text: 'hi', quick_replies: [botly.createQuickReply('option1', 'option_1')]}, ()=> {
botly.sendText({id: USER_ID, text: 'hi', quick_replies: [botly.createQuickReply('option1', 'option_1', 'http://google.com/someimage.png'), botly.createShareLocation()]}, ()=> {
});

expect(request.post.calledOnce).to.be.true;
Expand All @@ -595,7 +595,11 @@ describe('Botly Tests', function () {
{
'content_type': 'text',
'title': 'option1',
'payload': 'option_1'
'payload': 'option_1',
'image_url': 'http://google.com/someimage.png'
},
{
'content_type': 'location'
}
]
},
Expand All @@ -615,14 +619,15 @@ describe('Botly Tests', function () {
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH
});

botly.sendImage({id: USER_ID, url: 'http://image.com'});
botly.sendImage({id: USER_ID, url: 'http://image.com', is_reusable: true});

expect(request.post.calledOnce).to.be.true;
expect(request.post.args[0][0].body).to.eql({
'message': {
'attachment': {
'payload': {
'url': 'http://image.com'
'url': 'http://image.com',
'is_reusable': true
},
'type': 'image'
}
Expand All @@ -646,7 +651,7 @@ describe('Botly Tests', function () {
botly.sendButtons({
id: USER_ID,
text: 'What do you want to do next?',
buttons: botly.createPostbackButton('Continue', 'continue')
buttons: botly.createPostbackButton('Continue', 'continue'),
}, function (err, data) {
});

Expand Down Expand Up @@ -690,7 +695,7 @@ describe('Botly Tests', function () {
item_url: 'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg',
image_url: 'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg',
subtitle: 'Choose now!',
buttons: [botly.createWebURLButton('Go to Askrround', 'http://askrround.com'), botly.createAccountLinkButton('http://askrround.com/login')]
buttons: [botly.createWebURLButton('Go to Askrround', 'http://askrround.com'), botly.createAccountLinkButton('http://askrround.com/login'), botly.createShareButton()]
};
botly.sendGeneric({id: USER_ID, elements: element});

Expand All @@ -710,6 +715,9 @@ describe('Botly Tests', function () {
{
'type': 'account_link',
'url': 'http://askrround.com/login'
},
{
'type': 'element_share'
}
],
'image_url': 'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg',
Expand All @@ -731,6 +739,60 @@ describe('Botly Tests', function () {

});

it('should send webview buttons', () => {
var botly = new Botly({
accessToken: 'myToken',
verifyToken: 'myVerifyToken',
webHookPath: '/webhook',
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH
});

var element = {
title: 'What do you want to do next?',
item_url: 'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg',
image_url: 'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg',
subtitle: 'Choose now!',
buttons: [botly.createWebURLButton('Go to Askrround', 'http://askrround.com', Botly.CONST.WEBVIEW_HEIGHT_RATIO.COMPACT, true, 'http://askrround.com')]
};
botly.sendGeneric({id: USER_ID, elements: element});

expect(request.post.calledOnce).to.be.true;
expect(request.post.args[0][0].body).to.eql({
'message': {
'attachment': {
'payload': {
'elements': [
{
'buttons': [
{
'title': 'Go to Askrround',
'type': 'web_url',
'url': 'http://askrround.com',
'webview_height_ratio': 'compact',
'messenger_extensions': true,
'fallback_url': 'http://askrround.com'
}
],
'image_url': 'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg',
'item_url': 'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg',
'subtitle': 'Choose now!',
'title': 'What do you want to do next?'
}
],
'template_type': 'generic'
},
'type': 'template'
}
},
'notification_type': 'NO_PUSH',
'recipient': {
'id': '333'
}
});

});


it('should send receipt messages', () => {
var botly = new Botly({
accessToken: 'myToken',
Expand Down Expand Up @@ -978,6 +1040,28 @@ describe('Botly Tests', function () {

});


it('should setwhitelist', () => {
request.post.yields(null, {});
var botly = new Botly({
accessToken: 'myToken',
verifyToken: 'myVerifyToken',
webHookPath: '/webhook',
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH
});

botly.setWhiteList({whiteList: ["https://askhaley.com"], actionType: 'add'}, ()=> {
});

expect(request.post.calledOnce).to.be.true;
expect(request.post.args[0][0].body).to.eql({
'whitelisted_domains': ["https://askhaley.com"],
'setting_type': 'domain_whitelisting',
'domain_action_type': 'add'
});

});

it('should set persistent menu', () => {
request.post.yields(null, {});
var botly = new Botly({
Expand Down

0 comments on commit c5a166e

Please sign in to comment.