diff --git a/spec/line/bot/v2/misc_spec.rb b/spec/line/bot/v2/misc_spec.rb index 9a1dfa57..bcc436f3 100644 --- a/spec/line/bot/v2/misc_spec.rb +++ b/spec/line/bot/v2/misc_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'base64' describe 'misc' do let(:channel_access_token) { 'YOUR_CHANNEL_ACCESS_TOKEN' } @@ -672,6 +673,88 @@ end end + describe 'Client.new - base_url' do + describe 'normal client' do + let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token', base_url: 'https://example.com') } + let(:user_id) { 'u1234567890' } + let(:response_body) { { displayName: "LINE taro", userId: user_id, language: "en", pictureUrl: "https://profile.line-scdn.net/ch/v2/p/uf9da5ee2b...", statusMessage: "Hello, LINE!" }.to_json } + let(:response_code) { 200 } + + it 'allow to change base_url in normal client' do + path = "https://example.com/v2/bot/profile/#{user_id}" + stub_request(:get, path) + .with( + headers: { + 'Authorization' => "Bearer test-channel-access-token" + } + ) + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) + + body, status_code, headers = client.get_profile_with_http_info(user_id: user_id) + + expect(status_code).to eq(response_code) + expect(body.user_id).to eq(user_id) + end + end + + describe 'blob client' do + let(:client) { Line::Bot::V2::MessagingApi::ApiBlobClient.new(channel_access_token: 'test-channel-access-token', base_url: 'https://example.com') } + let(:response_body) { { status: "succeeded" }.to_json } + let(:response_code) { 200 } + + it 'allow to change base_url in blob client' do + path = "https://example.com/v2/bot/message/test-message-id/content/transcoding" + stub_request(:get, path) + .with( + headers: { + 'Authorization' => "Bearer test-channel-access-token" + } + ) + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) + + body, status_code, headers = client.get_message_content_transcoding_by_message_id_with_http_info(message_id: 'test-message-id') + expect(status_code).to eq(200) + expect(body.status).to eq('succeeded') + end + end + + describe 'module attach client' do + let(:client) { Line::Bot::V2::ModuleAttach::ApiClient.new(base_url: 'https://example.com', channel_id: '100000', channel_secret: 'test-channel-secret') } + let(:response_body) { { bot_id: "U111...", scopes: ["message:send", "message:receive"] }.to_json } + let(:response_code) { 200 } + + it 'allow to change base_url in module attach client' do + path = "https://example.com/module/auth/v1/token" + expected_authorization_header_value = Base64.strict_encode64("100000:test-channel-secret") + + stub_request(:post, path) + .with( + headers: { + 'Authorization' => "Basic #{expected_authorization_header_value}", + 'Content-Type' => 'application/x-www-form-urlencoded' + }, + body: { + 'grant_type' => 'authorization_code', + 'code' => 'test-code', + 'redirect_uri' => 'https://example2.com/callback?key=value', + 'scope' => 'message:send message:receive' + } + ) + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) + + body, status_code, headers = client.attach_module_with_http_info( + grant_type: 'authorization_code', + code: 'test-code', + redirect_uri: 'https://example2.com/callback?key=value', + scope: 'message:send message:receive' + ) + expect(status_code).to eq(200) + expect(body.bot_id).to eq('U111...') + expect(body.scopes).to eq(["message:send", "message:receive"]) + end + end + end + describe 'Line::Bot::V2::MessagingApi::TemplateMessage#initialize' do it "contains fixed type attribute" do template_message = Line::Bot::V2::MessagingApi::TemplateMessage.new(