|
340 | 340 | end |
341 | 341 | let(:response_code) { 200 } |
342 | 342 |
|
343 | | - it 'response - success' do |
| 343 | + it 'response - success - using Line::Bot::V2::MessagingApi::PushMessageRequest' do |
344 | 344 | stub_request(:post, "https://api.line.me/v2/bot/message/push") |
345 | 345 | .with( |
346 | 346 | headers: { |
347 | 347 | '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 |
349 | 359 | ) |
350 | 360 | .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
351 | 361 |
|
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) |
353 | 371 |
|
354 | 372 | expect(status_code).to eq(200) |
355 | 373 | expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse) |
|
358 | 376 | expect(body.sent_messages).to eq([{ id: '461230966842064897', quote_token: 'IStG5h1Tz7b...' }]) |
359 | 377 | end |
360 | 378 |
|
| 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 | + |
361 | 407 | it 'request with x_line_retry_key: nil' do |
362 | 408 | client = Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token-retry-key-nil') |
363 | 409 | retry_key = nil |
364 | 410 | stub_request(:post, "https://api.line.me/v2/bot/message/push") |
365 | 411 | .with( |
366 | 412 | headers: { |
367 | 413 | '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 |
369 | 425 | ) |
370 | 426 | .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
371 | 427 |
|
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 | + ) |
373 | 440 |
|
374 | 441 | expect(WebMock).to(have_requested(:post, "https://api.line.me/v2/bot/message/push") |
375 | 442 | .with { |req| !req.headers.key?("X-Line-Retry-Key") }) |
|
382 | 449 | headers: { |
383 | 450 | 'Authorization' => "Bearer test-channel-access-token", |
384 | 451 | '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 |
386 | 463 | ) |
387 | 464 | .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
388 | 465 |
|
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 | + ) |
391 | 478 | expect(status_code).to eq(200) |
392 | 479 | expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse) |
393 | 480 | # TODO: Add test after https://github.com/line/line-bot-sdk-ruby/issues/440 is resolved |
|
419 | 506 | headers: { |
420 | 507 | 'Authorization' => "Bearer test-channel-access-token", |
421 | 508 | '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 |
423 | 520 | ) |
424 | 521 | .to_return(status: 409, body: error_response_body, headers: error_response_headers) |
425 | 522 |
|
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 | + ) |
428 | 535 | expect(status_code).to eq(409) |
429 | 536 | expect(body).to be_a(Line::Bot::V2::MessagingApi::ErrorResponse) |
430 | 537 | expect(body.message).to eq("The retry key is already accepted") |
|
446 | 553 | .with( |
447 | 554 | headers: { |
448 | 555 | '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 |
450 | 566 | ) |
451 | 567 | .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
452 | 568 |
|
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) |
454 | 578 |
|
455 | 579 | expect(status_code).to eq(200) |
456 | 580 | expect(body).to eq("{}") |
|
467 | 591 | ) |
468 | 592 | .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
469 | 593 |
|
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) |
471 | 602 |
|
472 | 603 | expect(WebMock).to(have_requested(:post, "https://api.line.me/v2/bot/message/broadcast") |
473 | 604 | .with { |req| !req.headers.key?("X-Line-Retry-Key") }) |
|
484 | 615 | ) |
485 | 616 | .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
486 | 617 |
|
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) |
488 | 626 |
|
489 | 627 | expect(status_code).to eq(200) |
490 | 628 | expect(body).to eq("{}") |
|
510 | 648 | ) |
511 | 649 | .to_return(status: 409, body: error_response_body, headers: error_response_headers) |
512 | 650 |
|
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) |
514 | 659 |
|
515 | 660 | expect(status_code).to eq(409) |
516 | 661 | expect(body).to be_a(Line::Bot::V2::MessagingApi::ErrorResponse) |
|
0 commit comments