Skip to content

Fix NameError in v2 push_message due to missing VERSION constant #379

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

Closed
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lib/line/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

# V2
require 'line/bot/v2/webhook_parser'
require 'line/bot/v2/version'
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I think it may be good to write require ... where Line::Bot::V2::VERSION is used. In other words, I think it may be good to write the require ... in lib/line/bot/v2/http_client.rb. What do you think?


## OpenAPI
require 'line/bot/v2/channel_access_token/core'
Expand Down
35 changes: 35 additions & 0 deletions spec/line/bot/v2/misc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,39 @@
expect(body._next).to eq("token")
end
end

describe 'POST /v2/bot/message/push' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Even without this change in lib/line/bot.rb, the test passes. This means that the test cannot detect the same failure you encountered. Can you write a test that fails without the change in lib/line/bot.rb and succeeds with the patch in lib/line/bot.rb?

let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token') }
let(:response_body) { { "sentMessages" => [{ "id" => "461230966842064897", "quoteToken" => "IStG5h1Tz7b..." }] } }
let(:response_code) { 200 }
let(:x_line_retry_key) { SecureRandom.uuid }
let(:request_body) do
{
"to" => "U4af4980629",
"messages" => [
{
"type" => "text",
"text" => "Hello, world1"
}
]
}
end

it 'returns a sentMessages id' do
stub_request(:post, "https://api.line.me/v2/bot/message/push")
.with(
headers: {
"Authorization" => "Bearer test-channel-access-token",
"X-Line-Retry-Key" => x_line_retry_key
},
body: request_body.to_json
)
.to_return(status: response_code, body: response_body.to_json, headers: { 'Content-Type' => 'application/json' })

body, status_code, headers = client.push_message_with_http_info(push_message_request: request_body, x_line_retry_key: x_line_retry_key)

expect(status_code).to eq(200)
expect(body.sent_messages).to eq([{ id: "461230966842064897", quote_token: "IStG5h1Tz7b..." }])
end
end
end