|
202 | 202 | stub_request(:get, "https://api.line.me/v2/bot/message/progress/narrowcast?requestId=7d51557c-7ba0-4ed7-991f-36b2a340dc1a") |
203 | 203 | .with( |
204 | 204 | headers: { |
205 | | - 'Authorization'=>'Bearer YOUR_CHANNEL_ACCESS_TOKEN', |
| 205 | + 'Authorization' => 'Bearer YOUR_CHANNEL_ACCESS_TOKEN', |
206 | 206 | } |
207 | 207 | ) |
208 | 208 | .to_return(status: response_code, body: response_body, headers: { 'x-line-request-id' => '3a785346-2cf3-482f-8469-c893117fcef8' }) |
|
313 | 313 | 'Authorization' => "Bearer test-channel-access-token" |
314 | 314 | } |
315 | 315 | ) |
316 | | - .to_return(status: response_code, body: response_body, headers: { }) |
| 316 | + .to_return(status: response_code, body: response_body, headers: {}) |
317 | 317 |
|
318 | 318 | request = Line::Bot::V2::Liff::UpdateLiffAppRequest.new(view: { url: 'https://example.com' }) |
319 | 319 | body, status_code, headers = client.update_liff_app_with_http_info(liff_id: 'test-liff-id', update_liff_app_request: request) |
|
323 | 323 | end |
324 | 324 | end |
325 | 325 |
|
| 326 | + describe 'POST /v2/bot/message/push' do |
| 327 | + let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token') } |
| 328 | + let(:response_body) do |
| 329 | + { |
| 330 | + "sentMessages": [ |
| 331 | + { |
| 332 | + "id": "461230966842064897", |
| 333 | + "quoteToken": "IStG5h1Tz7b..." |
| 334 | + } |
| 335 | + ] |
| 336 | + }.to_json |
| 337 | + end |
| 338 | + let(:response_code) { 200 } |
| 339 | + |
| 340 | + it 'response - success' do |
| 341 | + stub_request(:post, "https://api.line.me/v2/bot/message/push") |
| 342 | + .with( |
| 343 | + headers: { |
| 344 | + 'Authorization' => "Bearer test-channel-access-token" |
| 345 | + } |
| 346 | + ) |
| 347 | + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
| 348 | + |
| 349 | + body, status_code, headers = client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' }) |
| 350 | + |
| 351 | + expect(status_code).to eq(200) |
| 352 | + expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse) |
| 353 | + # TODO: Add test after https://github.com/line/line-bot-sdk-ruby/issues/440 is resolved |
| 354 | + # We should access body.sent_messages[0].id and body.sent_messages[0].quote_token, but it's not possible now. |
| 355 | + expect(body.sent_messages).to eq([{ id: '461230966842064897', quote_token: 'IStG5h1Tz7b...' }]) |
| 356 | + end |
| 357 | + |
| 358 | + it 'request with x_line_retry_key: nil' do |
| 359 | + client = Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token-retry-key-nil') |
| 360 | + retry_key = nil |
| 361 | + stub_request(:post, "https://api.line.me/v2/bot/message/push") |
| 362 | + .with( |
| 363 | + headers: { |
| 364 | + 'Authorization' => "Bearer test-channel-access-token-retry-key-nil", |
| 365 | + } |
| 366 | + ) |
| 367 | + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
| 368 | + |
| 369 | + client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) |
| 370 | + |
| 371 | + expect(WebMock).to(have_requested(:post, "https://api.line.me/v2/bot/message/push") |
| 372 | + .with { |req| !req.headers.key?("X-Line-Retry-Key") }) |
| 373 | + end |
| 374 | + |
| 375 | + it 'request with x-line-retry-key header - success' do |
| 376 | + retry_key = 'f03c3eb4-0267-4080-9e65-fffa184e1933' |
| 377 | + stub_request(:post, "https://api.line.me/v2/bot/message/push") |
| 378 | + .with( |
| 379 | + headers: { |
| 380 | + 'Authorization' => "Bearer test-channel-access-token", |
| 381 | + 'X-Line-Retry-Key' => retry_key |
| 382 | + } |
| 383 | + ) |
| 384 | + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
| 385 | + |
| 386 | + body, status_code, headers = client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) |
| 387 | + |
| 388 | + expect(status_code).to eq(200) |
| 389 | + expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse) |
| 390 | + # TODO: Add test after https://github.com/line/line-bot-sdk-ruby/issues/440 is resolved |
| 391 | + # We should access body.sent_messages[0].id and body.sent_messages[0].quote_token, but it's not possible now. |
| 392 | + expect(body.sent_messages).to eq([{ id: '461230966842064897', quote_token: 'IStG5h1Tz7b...' }]) |
| 393 | + end |
| 394 | + |
| 395 | + it 'request with x-line-retry-key header - conflicted' do |
| 396 | + retry_key = '2a6e07b0-0fcf-439f-908b-828ed527e882' |
| 397 | + request_id = '3a785346-2cf3-482f-8469-c893117fcef8' |
| 398 | + accepted_request_id = '4a6e07b0-0fcf-439f-908b-828ed527e882' |
| 399 | + |
| 400 | + error_response_body = { |
| 401 | + "message" => "The retry key is already accepted", |
| 402 | + "sentMessages" => [ |
| 403 | + { |
| 404 | + "id" => "461230966842064897", |
| 405 | + "quoteToken" => "IStG5h1Tz7b..." |
| 406 | + } |
| 407 | + ] |
| 408 | + }.to_json |
| 409 | + error_response_headers = { |
| 410 | + 'Content-Type' => 'application/json', |
| 411 | + 'x-line-request-id' => request_id, |
| 412 | + 'x-line-accepted-request-id' => accepted_request_id |
| 413 | + } |
| 414 | + stub_request(:post, "https://api.line.me/v2/bot/message/push") |
| 415 | + .with( |
| 416 | + headers: { |
| 417 | + 'Authorization' => "Bearer test-channel-access-token", |
| 418 | + 'X-Line-Retry-Key' => retry_key |
| 419 | + } |
| 420 | + ) |
| 421 | + .to_return(status: 409, body: error_response_body, headers: error_response_headers) |
| 422 | + |
| 423 | + body, status_code, headers = client.push_message_with_http_info(push_message_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) |
| 424 | + |
| 425 | + expect(status_code).to eq(409) |
| 426 | + expect(body).to be_a(Line::Bot::V2::MessagingApi::ErrorResponse) |
| 427 | + expect(body.message).to eq("The retry key is already accepted") |
| 428 | + # TODO: Add test after https://github.com/line/line-bot-sdk-ruby/issues/440 is resolved. |
| 429 | + # We should access body.sent_messages[0].id and body.sent_messages[0].quote_token, but it's not possible now. |
| 430 | + expect(body.sent_messages).to eq([{ id: '461230966842064897', quote_token: 'IStG5h1Tz7b...' }]) |
| 431 | + expect(headers['x-line-request-id']).to eq(request_id) |
| 432 | + expect(headers['x-line-accepted-request-id']).to eq(accepted_request_id) |
| 433 | + end |
| 434 | + end |
| 435 | + |
326 | 436 | describe 'POST /v2/bot/message/broadcast' do |
327 | 437 | let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token') } |
328 | | - let(:response_body) { { }.to_json } # empty json |
| 438 | + let(:response_body) { {}.to_json } # empty json |
329 | 439 | let(:response_code) { 200 } |
330 | 440 |
|
331 | 441 | it 'empty json as response body should not throw error' do |
|
342 | 452 | expect(status_code).to eq(200) |
343 | 453 | expect(body).to eq("{}") |
344 | 454 | end |
| 455 | + |
| 456 | + it 'request with x_line_retry_key: nil' do |
| 457 | + client = Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token-retry-key-nil') |
| 458 | + retry_key = nil |
| 459 | + stub_request(:post, "https://api.line.me/v2/bot/message/broadcast") |
| 460 | + .with( |
| 461 | + headers: { |
| 462 | + 'Authorization' => "Bearer test-channel-access-token-retry-key-nil", |
| 463 | + } |
| 464 | + ) |
| 465 | + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
| 466 | + |
| 467 | + client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) |
| 468 | + |
| 469 | + expect(WebMock).to(have_requested(:post, "https://api.line.me/v2/bot/message/broadcast") |
| 470 | + .with { |req| !req.headers.key?("X-Line-Retry-Key") }) |
| 471 | + end |
| 472 | + |
| 473 | + it 'request with x-line-retry-key header - success' do |
| 474 | + retry_key = 'f03c3eb4-0267-4080-9e65-fffa184e1933' |
| 475 | + stub_request(:post, "https://api.line.me/v2/bot/message/broadcast") |
| 476 | + .with( |
| 477 | + headers: { |
| 478 | + 'Authorization' => "Bearer test-channel-access-token", |
| 479 | + 'X-Line-Retry-Key' => retry_key |
| 480 | + } |
| 481 | + ) |
| 482 | + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
| 483 | + |
| 484 | + body, status_code, headers = client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) |
| 485 | + |
| 486 | + expect(status_code).to eq(200) |
| 487 | + expect(body).to eq("{}") |
| 488 | + end |
| 489 | + |
| 490 | + it 'request with x-line-retry-key header - conflicted' do |
| 491 | + retry_key = '2a6e07b0-0fcf-439f-908b-828ed527e882' |
| 492 | + request_id = '3a785346-2cf3-482f-8469-c893117fcef8' |
| 493 | + accepted_request_id = '4a6e07b0-0fcf-439f-908b-828ed527e882' |
| 494 | + |
| 495 | + error_response_body = { "message" => "The retry key is already accepted" }.to_json |
| 496 | + error_response_headers = { |
| 497 | + 'Content-Type' => 'application/json', |
| 498 | + 'x-line-request-id' => request_id, |
| 499 | + 'x-line-accepted-request-id' => accepted_request_id |
| 500 | + } |
| 501 | + stub_request(:post, "https://api.line.me/v2/bot/message/broadcast") |
| 502 | + .with( |
| 503 | + headers: { |
| 504 | + 'Authorization' => "Bearer test-channel-access-token", |
| 505 | + 'X-Line-Retry-Key' => retry_key |
| 506 | + } |
| 507 | + ) |
| 508 | + .to_return(status: 409, body: error_response_body, headers: error_response_headers) |
| 509 | + |
| 510 | + body, status_code, headers = client.broadcast_with_http_info(broadcast_request: { type: 'text', text: 'Hello, world!' }, x_line_retry_key: retry_key) |
| 511 | + |
| 512 | + expect(status_code).to eq(409) |
| 513 | + expect(body).to be_a(Line::Bot::V2::MessagingApi::ErrorResponse) |
| 514 | + expect(body.message).to eq("The retry key is already accepted") |
| 515 | + expect(headers['x-line-request-id']).to eq(request_id) |
| 516 | + expect(headers['x-line-accepted-request-id']).to eq(accepted_request_id) |
| 517 | + end |
345 | 518 | end |
346 | 519 |
|
347 | 520 | describe 'GET /v2/bot/message/aggregation/list' do |
|
0 commit comments