Skip to content

Commit

Permalink
Merge pull request #63 from line/feature/support_datetimepicker
Browse files Browse the repository at this point in the history
Support datetimepicker, Fix #57
  • Loading branch information
hirohisa authored Oct 30, 2017
2 parents 2c04203 + 43b6a4e commit 22d6d5c
Showing 1 changed file with 135 additions and 0 deletions.
135 changes: 135 additions & 0 deletions spec/line/bot/send_message_14_template_datepicker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
require 'spec_helper'
require 'webmock/rspec'
require 'json'

WebMock.allow_net_connect!

describe Line::Bot::Client do

it 'pushes the template message type datepicker' do
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/push'
stub_request(:post, uri_template).to_return { |request| {:body => request.body, :status => 200} }

client = Line::Bot::Client.new do |config|
config.channel_token = 'channel_token'
end

user_id = 'user_id'
message = {
type: 'template',
altText: 'this is an template message',
template: {
type: 'buttons',
title: 'event schedule',
text: 'select date',
actions: [
{
type: 'datetimepicker',
label: 'ok',
data: 'datetimepicker=ok',
mode: 'date'
},
{
type: 'postback',
label: 'no',
data: 'datetimepicker=no',
},
]
}
}
response = client.push_message(user_id, message)

expected = {
to: user_id,
messages: [
message
]
}.to_json
expect(response.body).to eq(expected)
end

it 'replies the template message type carousel' do
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/reply'
stub_request(:post, uri_template).to_return { |request| {:body => request.body, :status => 200} }

client = Line::Bot::Client.new do |config|
config.channel_token = 'channel_token'
end

reply_token = 'reply_token'
message = {
type: 'template',
altText: 'this is an template message',
template: {
type: 'buttons',
title: 'event schedule',
text: 'select date',
actions: [
{
type: 'datetimepicker',
label: 'ok',
data: 'datetimepicker=ok',
mode: 'date'
},
{
type: 'postback',
label: 'no',
data: 'datetimepicker=no',
},
]
}
}
response = client.reply_message(reply_token, message)

expected = {
replyToken: reply_token,
messages: [
message
]
}.to_json
expect(response.body).to eq(expected)
end

it 'multicasts the template message type carousel' do
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/multicast'
stub_request(:post, uri_template).to_return { |request| {:body => request.body, :status => 200} }

client = Line::Bot::Client.new do |config|
config.channel_token = 'channel_token'
end

user_ids = ['user1', 'user2']
message = {
type: 'template',
altText: 'this is an template message',
template: {
type: 'buttons',
title: 'event schedule',
text: 'select date',
actions: [
{
type: 'datetimepicker',
label: 'ok',
data: 'datetimepicker=ok',
mode: 'date'
},
{
type: 'postback',
label: 'no',
data: 'datetimepicker=no',
},
]
}
}
response = client.multicast(user_ids, message)

expected = {
to: user_ids,
messages: [
message
]
}.to_json
expect(response.body).to eq(expected)
end

end

0 comments on commit 22d6d5c

Please sign in to comment.