-
Notifications
You must be signed in to change notification settings - Fork 128
Fix request content in messaging test #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,16 +340,34 @@ | |
| end | ||
| let(:response_code) { 200 } | ||
|
|
||
| it 'response - success' do | ||
| it 'response - success - using Line::Bot::V2::MessagingApi::PushMessageRequest' do | ||
| stub_request(:post, "https://api.line.me/v2/bot/message/push") | ||
| .with( | ||
| headers: { | ||
| 'Authorization' => "Bearer test-channel-access-token" | ||
| } | ||
| }, | ||
| body: { | ||
| "to" => "USER_ID", | ||
| "messages" => [ | ||
| { | ||
| "type" => "text", | ||
| "text" => " Hello, world! " | ||
| } | ||
| ], | ||
| "notificationDisabled" => false, | ||
| }.to_json | ||
| ) | ||
| .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| body, status_code, headers = client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' }) | ||
| request = Line::Bot::V2::MessagingApi::PushMessageRequest.new( | ||
| to: 'USER_ID', | ||
| messages: [ | ||
| Line::Bot::V2::MessagingApi::TextMessage.new( | ||
| text: ' Hello, world! ' | ||
| ) | ||
| ] | ||
| ) | ||
| body, status_code, headers = client.push_message_with_http_info(push_message_request: request) | ||
|
|
||
| expect(status_code).to eq(200) | ||
| expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse) | ||
|
|
@@ -358,18 +376,67 @@ | |
| expect(body.sent_messages).to eq([{ id: '461230966842064897', quote_token: 'IStG5h1Tz7b...' }]) | ||
| end | ||
|
|
||
| it 'response - success - using hash' do | ||
| stub_request(:post, "https://api.line.me/v2/bot/message/push") | ||
| .with( | ||
| headers: { | ||
| 'Authorization' => "Bearer test-channel-access-token" | ||
| }, | ||
| body: { | ||
| "to" => "USER_ID", | ||
| "messages" => [ | ||
| { | ||
| "type" => "text", | ||
| "text" => " Hello, world! " | ||
| } | ||
| ], | ||
| }.to_json | ||
| ) | ||
| .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| request = { | ||
| "to" => "USER_ID", | ||
| "messages" => [{ type: 'text', text: ' Hello, world! ' }] | ||
| } | ||
|
Comment on lines
+397
to
+400
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this (without using Q: I'm not sure if it's intentional. Is this intentional? @mokuzon
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not my intention to do so, but I do get a warning from RBS.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the reply. Since it wasn't intentional, let's remove the current behavior from the spec (i.e., don't explicitly mention it in the documentation, but leave the code as is). On the other hand, I thought that v1 users might appreciate this behavior when migrating to v2, as it makes the migration process much simpler. There's no need to actively rewrite the request object. If, in the future, this behavior becomes problematic for any SDK users, we can discontinue the current behavior. |
||
| body, status_code, headers = client.push_message_with_http_info(push_message_request: request) | ||
|
|
||
| expect(status_code).to eq(200) | ||
| expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse) | ||
| end | ||
|
|
||
| it 'request with x_line_retry_key: nil' do | ||
| client = Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token-retry-key-nil') | ||
| retry_key = nil | ||
| stub_request(:post, "https://api.line.me/v2/bot/message/push") | ||
| .with( | ||
| headers: { | ||
| 'Authorization' => "Bearer test-channel-access-token-retry-key-nil", | ||
| } | ||
| }, | ||
| body: { | ||
| "to" => "USER_ID", | ||
| "messages" => [ | ||
| { | ||
| "type" => "text", | ||
| "text" => "Hello, world!" | ||
| } | ||
| ], | ||
| "notificationDisabled" => false, | ||
| }.to_json | ||
| ) | ||
| .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) | ||
| request = Line::Bot::V2::MessagingApi::PushMessageRequest.new( | ||
| to: 'USER_ID', | ||
| messages: [ | ||
| Line::Bot::V2::MessagingApi::TextMessage.new( | ||
| text: 'Hello, world!' | ||
| ) | ||
| ] | ||
| ) | ||
| client.push_message_with_http_info( | ||
| push_message_request: request, | ||
| x_line_retry_key: retry_key | ||
| ) | ||
|
|
||
| expect(WebMock).to(have_requested(:post, "https://api.line.me/v2/bot/message/push") | ||
| .with { |req| !req.headers.key?("X-Line-Retry-Key") }) | ||
|
|
@@ -382,12 +449,32 @@ | |
| headers: { | ||
| 'Authorization' => "Bearer test-channel-access-token", | ||
| 'X-Line-Retry-Key' => retry_key | ||
| } | ||
| }, | ||
| body: { | ||
| "to" => "USER_ID", | ||
| "messages" => [ | ||
| { | ||
| "type" => "text", | ||
| "text" => "Hello, world!" | ||
| } | ||
| ], | ||
| "notificationDisabled" => false, | ||
| }.to_json | ||
| ) | ||
| .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| body, status_code, headers = client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) | ||
|
|
||
| request = Line::Bot::V2::MessagingApi::PushMessageRequest.new( | ||
| to: 'USER_ID', | ||
| messages: [ | ||
| Line::Bot::V2::MessagingApi::TextMessage.new( | ||
| text: 'Hello, world!' | ||
| ) | ||
| ] | ||
| ) | ||
| body, status_code, headers = client.push_message_with_http_info( | ||
| push_message_request: request, | ||
| x_line_retry_key: retry_key | ||
| ) | ||
| expect(status_code).to eq(200) | ||
| expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse) | ||
| # TODO: Add test after https://github.com/line/line-bot-sdk-ruby/issues/440 is resolved | ||
|
|
@@ -419,12 +506,32 @@ | |
| headers: { | ||
| 'Authorization' => "Bearer test-channel-access-token", | ||
| 'X-Line-Retry-Key' => retry_key | ||
| } | ||
| }, | ||
| body: { | ||
| "to" => "USER_ID", | ||
| "messages" => [ | ||
| { | ||
| "type" => "text", | ||
| "text" => "Hello, world!" | ||
| } | ||
| ], | ||
| "notificationDisabled" => false, | ||
| }.to_json | ||
| ) | ||
| .to_return(status: 409, body: error_response_body, headers: error_response_headers) | ||
|
|
||
| body, status_code, headers = client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) | ||
|
|
||
| request = Line::Bot::V2::MessagingApi::PushMessageRequest.new( | ||
| to: 'USER_ID', | ||
| messages: [ | ||
| Line::Bot::V2::MessagingApi::TextMessage.new( | ||
| text: 'Hello, world!' | ||
| ) | ||
| ] | ||
| ) | ||
| body, status_code, headers = client.push_message_with_http_info( | ||
| push_message_request: request, | ||
| x_line_retry_key: retry_key | ||
| ) | ||
| expect(status_code).to eq(409) | ||
| expect(body).to be_a(Line::Bot::V2::MessagingApi::ErrorResponse) | ||
| expect(body.message).to eq("The retry key is already accepted") | ||
|
|
@@ -446,11 +553,28 @@ | |
| .with( | ||
| headers: { | ||
| 'Authorization' => "Bearer test-channel-access-token" | ||
| } | ||
| }, | ||
| body: { | ||
| "messages" => [ | ||
| { | ||
| "type" => "text", | ||
| "text" => "Hello, world!" | ||
| } | ||
| ], | ||
| "notificationDisabled" => false, | ||
| }.to_json | ||
| ) | ||
| .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| body, status_code, headers = client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' }) | ||
| request = Line::Bot::V2::MessagingApi::BroadcastRequest.new( | ||
| messages: [ | ||
| Line::Bot::V2::MessagingApi::TextMessage.new( | ||
| text: 'Hello, world!' | ||
| ) | ||
| ] | ||
| ) | ||
|
|
||
| body, status_code, headers = client.broadcast_with_http_info(broadcast_request: request) | ||
|
|
||
| expect(status_code).to eq(200) | ||
| expect(body).to eq("{}") | ||
|
|
@@ -467,7 +591,14 @@ | |
| ) | ||
| .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) | ||
| request = Line::Bot::V2::MessagingApi::BroadcastRequest.new( | ||
| messages: [ | ||
| Line::Bot::V2::MessagingApi::TextMessage.new( | ||
| text: 'Hello, world!' | ||
| ) | ||
| ] | ||
| ) | ||
| client.broadcast_with_http_info(broadcast_request: request, x_line_retry_key: retry_key) | ||
|
|
||
| expect(WebMock).to(have_requested(:post, "https://api.line.me/v2/bot/message/broadcast") | ||
| .with { |req| !req.headers.key?("X-Line-Retry-Key") }) | ||
|
|
@@ -484,7 +615,14 @@ | |
| ) | ||
| .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) | ||
|
|
||
| body, status_code, headers = client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) | ||
| request = Line::Bot::V2::MessagingApi::BroadcastRequest.new( | ||
| messages: [ | ||
| Line::Bot::V2::MessagingApi::TextMessage.new( | ||
| text: 'Hello, world!' | ||
| ) | ||
| ] | ||
| ) | ||
| body, status_code, headers = client.broadcast_with_http_info(broadcast_request: request, x_line_retry_key: retry_key) | ||
|
|
||
| expect(status_code).to eq(200) | ||
| expect(body).to eq("{}") | ||
|
|
@@ -510,7 +648,14 @@ | |
| ) | ||
| .to_return(status: 409, body: error_response_body, headers: error_response_headers) | ||
|
|
||
| body, status_code, headers = client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) | ||
| request = Line::Bot::V2::MessagingApi::BroadcastRequest.new( | ||
| messages: [ | ||
| Line::Bot::V2::MessagingApi::TextMessage.new( | ||
| text: 'Hello, world!' | ||
| ) | ||
| ] | ||
| ) | ||
| body, status_code, headers = client.broadcast_with_http_info(broadcast_request: request, x_line_retry_key: retry_key) | ||
|
|
||
| expect(status_code).to eq(409) | ||
| expect(body).to be_a(Line::Bot::V2::MessagingApi::ErrorResponse) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.