Skip to content

Commit b632f42

Browse files
authored
Add test text v2 (#458)
1 parent ebf88ca commit b632f42

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

spec/line/bot/v2/misc_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,58 @@
405405
expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse)
406406
end
407407

408+
it 'request - text message v2' do
409+
stub_request(:post, "https://api.line.me/v2/bot/message/push")
410+
.with(
411+
headers: {
412+
'Authorization' => "Bearer test-channel-access-token"
413+
},
414+
body: {
415+
"to" => "USER_ID",
416+
"messages" => [
417+
{
418+
"type" => "textV2",
419+
"text" => " Hello, world! {name} san!",
420+
"substitution" => {
421+
"name" => {
422+
"type" => "mention",
423+
"mentionee" => {
424+
"type" => "user",
425+
"userId" => "U1234567890"
426+
}
427+
}
428+
}
429+
}
430+
],
431+
"notificationDisabled" => false,
432+
}.to_json
433+
)
434+
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
435+
436+
request = Line::Bot::V2::MessagingApi::PushMessageRequest.new(
437+
to: 'USER_ID',
438+
messages: [
439+
Line::Bot::V2::MessagingApi::TextMessageV2.new(
440+
text: ' Hello, world! {name} san!',
441+
substitution: {
442+
"name": Line::Bot::V2::MessagingApi::MentionSubstitutionObject.new(
443+
mentionee: Line::Bot::V2::MessagingApi::UserMentionTarget.new(
444+
user_id: 'U1234567890'
445+
)
446+
)
447+
}
448+
)
449+
]
450+
)
451+
body, status_code, headers = client.push_message_with_http_info(push_message_request: request)
452+
453+
expect(status_code).to eq(200)
454+
expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse)
455+
# TODO: Add test after https://github.com/line/line-bot-sdk-ruby/issues/440 is resolved
456+
# We should access body.sent_messages[0].id and body.sent_messages[0].quote_token, but it's not possible now.
457+
expect(body.sent_messages).to eq([{ id: '461230966842064897', quote_token: 'IStG5h1Tz7b...' }])
458+
end
459+
408460
it 'request with x_line_retry_key: nil' do
409461
client = Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token-retry-key-nil')
410462
retry_key = nil

0 commit comments

Comments
 (0)