Skip to content

Commit 7a1b9e6

Browse files
committed
NO-ISSUE Fix request content in messaging test
1 parent c7e6093 commit 7a1b9e6

File tree

1 file changed

+161
-16
lines changed

1 file changed

+161
-16
lines changed

spec/line/bot/v2/misc_spec.rb

Lines changed: 161 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,34 @@
340340
end
341341
let(:response_code) { 200 }
342342

343-
it 'response - success' do
343+
it 'response - success - using Line::Bot::V2::MessagingApi::PushMessageRequest' do
344344
stub_request(:post, "https://api.line.me/v2/bot/message/push")
345345
.with(
346346
headers: {
347347
'Authorization' => "Bearer test-channel-access-token"
348-
}
348+
},
349+
body: {
350+
"to" => "USER_ID",
351+
"messages" => [
352+
{
353+
"type" => "text",
354+
"text" => " Hello, world! "
355+
}
356+
],
357+
"notificationDisabled" => false,
358+
}.to_json
349359
)
350360
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
351361

352-
body, status_code, headers = client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' })
362+
request = Line::Bot::V2::MessagingApi::PushMessageRequest.new(
363+
to: 'USER_ID',
364+
messages: [
365+
Line::Bot::V2::MessagingApi::TextMessage.new(
366+
text: ' Hello, world! '
367+
)
368+
]
369+
)
370+
body, status_code, headers = client.push_message_with_http_info(push_message_request: request)
353371

354372
expect(status_code).to eq(200)
355373
expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse)
@@ -358,18 +376,67 @@
358376
expect(body.sent_messages).to eq([{ id: '461230966842064897', quote_token: 'IStG5h1Tz7b...' }])
359377
end
360378

379+
it 'response - success - using hash' do
380+
stub_request(:post, "https://api.line.me/v2/bot/message/push")
381+
.with(
382+
headers: {
383+
'Authorization' => "Bearer test-channel-access-token"
384+
},
385+
body: {
386+
"to" => "USER_ID",
387+
"messages" => [
388+
{
389+
"type" => "text",
390+
"text" => " Hello, world! "
391+
}
392+
],
393+
}.to_json
394+
)
395+
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
396+
397+
request = {
398+
"to" => "USER_ID",
399+
"messages" => [{ type: 'text', text: ' Hello, world! ' }]
400+
}
401+
body, status_code, headers = client.push_message_with_http_info(push_message_request: request)
402+
403+
expect(status_code).to eq(200)
404+
expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse)
405+
end
406+
361407
it 'request with x_line_retry_key: nil' do
362408
client = Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token-retry-key-nil')
363409
retry_key = nil
364410
stub_request(:post, "https://api.line.me/v2/bot/message/push")
365411
.with(
366412
headers: {
367413
'Authorization' => "Bearer test-channel-access-token-retry-key-nil",
368-
}
414+
},
415+
body: {
416+
"to" => "USER_ID",
417+
"messages" => [
418+
{
419+
"type" => "text",
420+
"text" => "Hello, world!"
421+
}
422+
],
423+
"notificationDisabled" => false,
424+
}.to_json
369425
)
370426
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
371427

372-
client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key)
428+
request = Line::Bot::V2::MessagingApi::PushMessageRequest.new(
429+
to: 'USER_ID',
430+
messages: [
431+
Line::Bot::V2::MessagingApi::TextMessage.new(
432+
text: 'Hello, world!'
433+
)
434+
]
435+
)
436+
client.push_message_with_http_info(
437+
push_message_request: request,
438+
x_line_retry_key: retry_key
439+
)
373440

374441
expect(WebMock).to(have_requested(:post, "https://api.line.me/v2/bot/message/push")
375442
.with { |req| !req.headers.key?("X-Line-Retry-Key") })
@@ -382,12 +449,32 @@
382449
headers: {
383450
'Authorization' => "Bearer test-channel-access-token",
384451
'X-Line-Retry-Key' => retry_key
385-
}
452+
},
453+
body: {
454+
"to" => "USER_ID",
455+
"messages" => [
456+
{
457+
"type" => "text",
458+
"text" => "Hello, world!"
459+
}
460+
],
461+
"notificationDisabled" => false,
462+
}.to_json
386463
)
387464
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
388465

389-
body, status_code, headers = client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key)
390-
466+
request = Line::Bot::V2::MessagingApi::PushMessageRequest.new(
467+
to: 'USER_ID',
468+
messages: [
469+
Line::Bot::V2::MessagingApi::TextMessage.new(
470+
text: 'Hello, world!'
471+
)
472+
]
473+
)
474+
body, status_code, headers = client.push_message_with_http_info(
475+
push_message_request: request,
476+
x_line_retry_key: retry_key
477+
)
391478
expect(status_code).to eq(200)
392479
expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse)
393480
# TODO: Add test after https://github.com/line/line-bot-sdk-ruby/issues/440 is resolved
@@ -419,12 +506,32 @@
419506
headers: {
420507
'Authorization' => "Bearer test-channel-access-token",
421508
'X-Line-Retry-Key' => retry_key
422-
}
509+
},
510+
body: {
511+
"to" => "USER_ID",
512+
"messages" => [
513+
{
514+
"type" => "text",
515+
"text" => "Hello, world!"
516+
}
517+
],
518+
"notificationDisabled" => false,
519+
}.to_json
423520
)
424521
.to_return(status: 409, body: error_response_body, headers: error_response_headers)
425522

426-
body, status_code, headers = client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key)
427-
523+
request = Line::Bot::V2::MessagingApi::PushMessageRequest.new(
524+
to: 'USER_ID',
525+
messages: [
526+
Line::Bot::V2::MessagingApi::TextMessage.new(
527+
text: 'Hello, world!'
528+
)
529+
]
530+
)
531+
body, status_code, headers = client.push_message_with_http_info(
532+
push_message_request: request,
533+
x_line_retry_key: retry_key
534+
)
428535
expect(status_code).to eq(409)
429536
expect(body).to be_a(Line::Bot::V2::MessagingApi::ErrorResponse)
430537
expect(body.message).to eq("The retry key is already accepted")
@@ -446,11 +553,28 @@
446553
.with(
447554
headers: {
448555
'Authorization' => "Bearer test-channel-access-token"
449-
}
556+
},
557+
body: {
558+
"messages" => [
559+
{
560+
"type" => "text",
561+
"text" => "Hello, world!"
562+
}
563+
],
564+
"notificationDisabled" => false,
565+
}.to_json
450566
)
451567
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
452568

453-
body, status_code, headers = client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' })
569+
request = Line::Bot::V2::MessagingApi::BroadcastRequest.new(
570+
messages: [
571+
Line::Bot::V2::MessagingApi::TextMessage.new(
572+
text: 'Hello, world!'
573+
)
574+
]
575+
)
576+
577+
body, status_code, headers = client.broadcast_with_http_info(broadcast_request: request)
454578

455579
expect(status_code).to eq(200)
456580
expect(body).to eq("{}")
@@ -467,7 +591,14 @@
467591
)
468592
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
469593

470-
client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key)
594+
request = Line::Bot::V2::MessagingApi::BroadcastRequest.new(
595+
messages: [
596+
Line::Bot::V2::MessagingApi::TextMessage.new(
597+
text: 'Hello, world!'
598+
)
599+
]
600+
)
601+
client.broadcast_with_http_info(broadcast_request: request, x_line_retry_key: retry_key)
471602

472603
expect(WebMock).to(have_requested(:post, "https://api.line.me/v2/bot/message/broadcast")
473604
.with { |req| !req.headers.key?("X-Line-Retry-Key") })
@@ -484,7 +615,14 @@
484615
)
485616
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
486617

487-
body, status_code, headers = client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key)
618+
request = Line::Bot::V2::MessagingApi::BroadcastRequest.new(
619+
messages: [
620+
Line::Bot::V2::MessagingApi::TextMessage.new(
621+
text: 'Hello, world!'
622+
)
623+
]
624+
)
625+
body, status_code, headers = client.broadcast_with_http_info(broadcast_request: request, x_line_retry_key: retry_key)
488626

489627
expect(status_code).to eq(200)
490628
expect(body).to eq("{}")
@@ -510,7 +648,14 @@
510648
)
511649
.to_return(status: 409, body: error_response_body, headers: error_response_headers)
512650

513-
body, status_code, headers = client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key)
651+
request = Line::Bot::V2::MessagingApi::BroadcastRequest.new(
652+
messages: [
653+
Line::Bot::V2::MessagingApi::TextMessage.new(
654+
text: 'Hello, world!'
655+
)
656+
]
657+
)
658+
body, status_code, headers = client.broadcast_with_http_info(broadcast_request: request, x_line_retry_key: retry_key)
514659

515660
expect(status_code).to eq(409)
516661
expect(body).to be_a(Line::Bot::V2::MessagingApi::ErrorResponse)

0 commit comments

Comments
 (0)