Skip to content

Commit 41742e4

Browse files
committed
merge
1 parent d9366ab commit 41742e4

1 file changed

Lines changed: 0 additions & 288 deletions

File tree

spec/line/bot/v2/misc_spec.rb

Lines changed: 0 additions & 288 deletions
Original file line numberDiff line numberDiff line change
@@ -743,292 +743,4 @@
743743
expect(body._next).to eq("token")
744744
end
745745
end
746-
747-
describe 'Same endpoint but different HTTP method' do
748-
let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token') }
749-
let(:rich_menu_id) { "richmenuid" }
750-
751-
describe 'GET /v2/bot/user/all/richmenu' do
752-
let(:response_body) { { richMenuId: rich_menu_id }.to_json }
753-
let(:response_code) { 200 }
754-
755-
it 'returns a default rich menu ID successfully' do
756-
stub_request(:get, "https://api.line.me/v2/bot/user/all/richmenu")
757-
.with(
758-
headers: {
759-
'Authorization' => "Bearer test-channel-access-token"
760-
}
761-
)
762-
.to_return(status: response_code, body: response_body, headers: {})
763-
764-
body, status_code, headers = client.get_default_rich_menu_id_with_http_info
765-
766-
expect(status_code).to eq(response_code)
767-
expect(body.rich_menu_id).to eq(rich_menu_id)
768-
end
769-
end
770-
771-
describe 'POST /v2/bot/user/all/richmenu' do
772-
let(:response_body) { {}.to_json }
773-
let(:response_code) { 200 }
774-
775-
it 'sets the default rich menu successfully' do
776-
stub_request(:post, "https://api.line.me/v2/bot/user/all/richmenu/#{rich_menu_id}")
777-
.with(
778-
headers: {
779-
'Authorization' => "Bearer test-channel-access-token"
780-
}
781-
)
782-
.to_return(status: response_code, body: '{}', headers: {})
783-
784-
body, status_code, headers = client.set_default_rich_menu_with_http_info(rich_menu_id: rich_menu_id)
785-
786-
expect(status_code).to eq(response_code)
787-
expect(body).to eq(response_body)
788-
end
789-
end
790-
791-
describe 'DELETE /v2/bot/user/all/richmenu' do
792-
let(:response_body) { {}.to_json }
793-
let(:response_code) { 200 }
794-
795-
it 'deletes the default rich menu successfully' do
796-
stub_request(:delete, "https://api.line.me/v2/bot/user/all/richmenu")
797-
.with(
798-
headers: {
799-
'Authorization' => "Bearer test-channel-access-token"
800-
}
801-
)
802-
.to_return(status: response_code, body: '{}', headers: {})
803-
804-
# Call the API method
805-
body, status_code, headers = client.cancel_default_rich_menu_with_http_info
806-
807-
# Assertions
808-
expect(status_code).to eq(200)
809-
expect(body).to eq(response_body)
810-
end
811-
end
812-
end
813-
814-
describe 'HTTP Request' do
815-
let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token') }
816-
let(:user_id) { 'u1234567890' }
817-
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 }
818-
let(:response_code) { 200 }
819-
820-
it 'has correct User-Agent header' do
821-
path = "https://api.line.me/v2/bot/profile/#{user_id}"
822-
stub_request(:get, path)
823-
.with(
824-
headers: {
825-
'Authorization' => "Bearer test-channel-access-token"
826-
}
827-
)
828-
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
829-
830-
body, status_code, headers = client.get_profile_with_http_info(user_id: user_id)
831-
832-
expect(status_code).to eq(response_code)
833-
expect(body.user_id).to eq(user_id)
834-
expect(WebMock).to have_requested(:get, path).
835-
with(headers: { 'User-Agent' => "LINE-BotSDK-Ruby/#{Line::Bot::V2::VERSION}" })
836-
end
837-
end
838-
839-
describe 'Unknown responses' do
840-
describe 'like unknown fields' do
841-
describe 'POST /v2/bot/message/reply' do
842-
let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token') }
843-
let(:response_body) { { sentMessages: [{ id: "461230966842064897", quoteToken: "IStG5h1Tz7b..." }], invalidField: "foobar" }.to_json }
844-
let(:response_code) { 200 }
845-
846-
it 'handles unknown fields in the response' do
847-
stub_request(:post, "https://api.line.me/v2/bot/message/reply")
848-
.with(
849-
headers: {
850-
'Authorization' => "Bearer test-channel-access-token",
851-
'Content-Type' => 'application/json'
852-
},
853-
body: anything
854-
)
855-
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
856-
857-
request = Line::Bot::V2::MessagingApi::ReplyMessageRequest.new(
858-
reply_token: 'test-reply-token',
859-
messages: [
860-
Line::Bot::V2::MessagingApi::TextMessage.new(
861-
text: 'Hello, world!'
862-
)
863-
]
864-
)
865-
866-
body, status_code, headers = client.reply_message_with_http_info(
867-
reply_message_request: request
868-
)
869-
870-
expect(status_code).to eq(response_code)
871-
expect(body.invalid_field).to eq("foobar")
872-
end
873-
end
874-
end
875-
end
876-
877-
describe 'Client.new - base_url' do
878-
describe 'normal client' do
879-
let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token', base_url: 'https://example.com') }
880-
let(:user_id) { 'u1234567890' }
881-
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 }
882-
let(:response_code) { 200 }
883-
884-
it 'allow to change base_url in normal client' do
885-
path = "https://example.com/v2/bot/profile/#{user_id}"
886-
stub_request(:get, path)
887-
.with(
888-
headers: {
889-
'Authorization' => "Bearer test-channel-access-token"
890-
}
891-
)
892-
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
893-
894-
body, status_code, headers = client.get_profile_with_http_info(user_id: user_id)
895-
896-
expect(status_code).to eq(response_code)
897-
expect(body.user_id).to eq(user_id)
898-
end
899-
end
900-
901-
describe 'blob client' do
902-
let(:client) { Line::Bot::V2::MessagingApi::ApiBlobClient.new(channel_access_token: 'test-channel-access-token', base_url: 'https://example.com') }
903-
let(:response_body) { { status: "succeeded" }.to_json }
904-
let(:response_code) { 200 }
905-
906-
it 'allow to change base_url in blob client' do
907-
path = "https://example.com/v2/bot/message/test-message-id/content/transcoding"
908-
stub_request(:get, path)
909-
.with(
910-
headers: {
911-
'Authorization' => "Bearer test-channel-access-token"
912-
}
913-
)
914-
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
915-
916-
body, status_code, headers = client.get_message_content_transcoding_by_message_id_with_http_info(message_id: 'test-message-id')
917-
expect(status_code).to eq(200)
918-
expect(body.status).to eq('succeeded')
919-
end
920-
end
921-
922-
describe 'module attach client' do
923-
let(:client) { Line::Bot::V2::ModuleAttach::ApiClient.new(base_url: 'https://example.com', channel_id: '100000', channel_secret: 'test-channel-secret') }
924-
let(:response_body) { { bot_id: "U111...", scopes: ["message:send", "message:receive"] }.to_json }
925-
let(:response_code) { 200 }
926-
927-
it 'allow to change base_url in module attach client' do
928-
path = "https://example.com/module/auth/v1/token"
929-
expected_authorization_header_value = Base64.strict_encode64("100000:test-channel-secret")
930-
931-
stub_request(:post, path)
932-
.with(
933-
headers: {
934-
'Authorization' => "Basic #{expected_authorization_header_value}",
935-
'Content-Type' => 'application/x-www-form-urlencoded'
936-
},
937-
body: {
938-
'grant_type' => 'authorization_code',
939-
'code' => 'test-code',
940-
'redirect_uri' => 'https://example2.com/callback?key=value',
941-
'scope' => 'message:send message:receive'
942-
}
943-
)
944-
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
945-
946-
body, status_code, headers = client.attach_module_with_http_info(
947-
grant_type: 'authorization_code',
948-
code: 'test-code',
949-
redirect_uri: 'https://example2.com/callback?key=value',
950-
scope: 'message:send message:receive'
951-
)
952-
expect(status_code).to eq(200)
953-
expect(body.bot_id).to eq('U111...')
954-
expect(body.scopes).to eq(["message:send", "message:receive"])
955-
end
956-
end
957-
end
958-
959-
describe 'Line::Bot::V2::MessagingApi::TemplateMessage#initialize' do
960-
it "contains fixed type attribute" do
961-
template_message = Line::Bot::V2::MessagingApi::TemplateMessage.new(
962-
alt_text: 'Test Alt Text',
963-
template: Line::Bot::V2::MessagingApi::ButtonsTemplate.new(
964-
text: 'Test Text',
965-
actions: [],
966-
title: 'Test Title'
967-
)
968-
)
969-
970-
expect(template_message.type).to eq('template')
971-
end
972-
end
973-
974-
describe 'Line::Bot::V2::MessagingApi::FlexMessage#initialize' do
975-
let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token') }
976-
977-
it "contains fixed type attribute (check in request body), and optional fields don't require input on initialize" do
978-
flex_message = Line::Bot::V2::MessagingApi::FlexMessage.new(
979-
alt_text: 'Test Alt Text',
980-
contents: Line::Bot::V2::MessagingApi::FlexBubble.new( # FlexBubble has many optional fields
981-
direction: 'ltr',
982-
body: Line::Bot::V2::MessagingApi::FlexBox.new(
983-
layout: 'vertical',
984-
contents: [
985-
Line::Bot::V2::MessagingApi::FlexText.new(
986-
text: 'Test Text',
987-
weight: 'bold'
988-
)
989-
]
990-
)
991-
),
992-
quick_reply: Line::Bot::V2::MessagingApi::QuickReply.new(
993-
items: []
994-
)
995-
)
996-
997-
expected_body = {
998-
messages: [
999-
{
1000-
type: 'flex',
1001-
altText: 'Test Alt Text',
1002-
contents: {
1003-
type: 'bubble',
1004-
direction: 'ltr',
1005-
body: {
1006-
type: 'box',
1007-
layout: 'vertical',
1008-
contents: [
1009-
{
1010-
type: 'text',
1011-
text: 'Test Text',
1012-
weight: 'bold'
1013-
}
1014-
]
1015-
}
1016-
}
1017-
}
1018-
],
1019-
notificationDisabled: false
1020-
}.to_json
1021-
1022-
stub_request(:post, "https://api.line.me/v2/bot/message/broadcast")
1023-
.with(
1024-
headers: {
1025-
'Authorization' => "Bearer test-channel-access-token"
1026-
},
1027-
body: expected_body
1028-
)
1029-
.to_return(status: 200, body: "{}", headers: { 'Content-Type' => 'application/json' })
1030-
1031-
client.broadcast_with_http_info(broadcast_request: Line::Bot::V2::MessagingApi::BroadcastRequest.new(messages: [flex_message]))
1032-
end
1033-
end
1034746
end

0 commit comments

Comments
 (0)