Skip to content

Commit 7c47315

Browse files
committed
NO-ISSUE Add test for text message v2
1 parent 7a1b9e6 commit 7c47315

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
@@ -404,6 +404,58 @@
404404
expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse)
405405
end
406406

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

0 commit comments

Comments
 (0)