Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions spec/line/bot/v2/misc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -686,4 +686,56 @@
expect(template_message.type).to eq('template')
end
end

describe 'Line::Bot::V2::MessagingApi::FlexMessage#initialize' do
let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token') }

it "contains fixed type attribute (check in request body), and optional fields don't require input on initialize" do
flex_message = Line::Bot::V2::MessagingApi::FlexMessage.new(
alt_text: 'Test Alt Text',
contents: Line::Bot::V2::MessagingApi::FlexBubble.new( # FlexBubble has many optional fields
direction: 'ltr',
body: Line::Bot::V2::MessagingApi::FlexText.new(
text: 'Test Text',
weight: 'bold',
size: 'xl'
)
),
quick_reply: Line::Bot::V2::MessagingApi::QuickReply.new(
items: []
)
)

expected_body = {
messages: [
{
type: 'flex',
altText: 'Test Alt Text',
contents: {
type: 'bubble',
direction: 'ltr',
body: {
type: 'text',
text: 'Test Text',
size: 'xl',
weight: 'bold'
}
}
}
],
notificationDisabled: false
}.to_json

stub_request(:post, "https://api.line.me/v2/bot/message/broadcast")
.with(
headers: {
'Authorization' => "Bearer test-channel-access-token"
},
body: expected_body
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

     
     WebMock::NetConnectNotAllowedError:
       Real HTTP connections are disabled. Unregistered request: POST https://api.line.me/v2/bot/message/broadcast with body '{"messages":[{"type":"flex","alt_text":"Test Alt Text","contents":{"type":"bubble","direction":"ltr","body":{"type":"text","text":"Test Text","size":"xl","weight":"bold"}}}],"notificationDisabled":false}' with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer test-channel-access-token', 'Content-Type'=>'application/json', 'Host'=>'api.line.me', 'User-Agent'=>'LINE-BotSDK-Ruby/2.0.0'}
     
       You can stub this request with the following snippet:
     
       stub_request(:post, "https://api.line.me/v2/bot/message/broadcast").
         with(
           body: "{\"messages\":[{\"type\":\"flex\",\"alt_text\":\"Test Alt Text\",\"contents\":{\"type\":\"bubble\",\"direction\":\"ltr\",\"body\":{\"type\":\"text\",\"text\":\"Test Text\",\"size\":\"xl\",\"weight\":\"bold\"}}}],\"notificationDisabled\":false}",
           headers: {
          'Accept'=>'*/*',
          'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
          'Authorization'=>'Bearer test-channel-access-token',
          'Content-Type'=>'application/json',
          'Host'=>'api.line.me',
          'User-Agent'=>'LINE-BotSDK-Ruby/2.0.0'
           }).
         to_return(status: 200, body: "", headers: {})
     
       registered request stubs:
     
       stub_request(:post, "https://api.line.me/v2/bot/message/broadcast").
         with(
           body: "{\"messages\":[{\"type\":\"flex\",\"altText\":\"Test Alt Text\",\"contents\":{\"type\":\"bubble\",\"direction\":\"ltr\",\"body\":{\"type\":\"text\",\"text\":\"Test Text\",\"size\":\"xl\",\"weight\":\"bold\"}}}],\"notificationDisabled\":false}",
           headers: {
          'Authorization'=>'Bearer test-channel-access-token'
           })
     
       Body diff:
        [["-", "messages[0].alt_text", "Test Alt Text"],
        ["+", "messages[0].altText", "Test Alt Text"]]

alt_text in Line::Bot::V2::MessagingApi::FlexMessage sends as alt_text(wrong), not altText(correct)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's related to #448 ..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#455 fixed this, thank you!

)
.to_return(status: 200, body: "{}", headers: { 'Content-Type' => 'application/json' })

client.broadcast_with_http_info(broadcast_request: Line::Bot::V2::MessagingApi::BroadcastRequest.new(messages: [flex_message]))
end
end
end