|
| 1 | +require 'spec_helper' |
| 2 | +require 'webmock/rspec' |
| 3 | + |
| 4 | +DELIVERY_RESULT_CONTENT = <<~"EOS" |
| 5 | +{ |
| 6 | + "status": "ready", |
| 7 | + "success": 3 |
| 8 | +} |
| 9 | +EOS |
| 10 | + |
| 11 | +describe Line::Bot::Client do |
| 12 | + describe '#push_pnp' do |
| 13 | + before do |
| 14 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + '/bot/pnp/push' |
| 15 | + stub_request(:post, uri_template).to_return { |request| { body: '{}', status: 200 } } |
| 16 | + end |
| 17 | + |
| 18 | + let(:client) do |
| 19 | + Line::Bot::Client.new do |config| |
| 20 | + config.channel_token = 'channel_token' |
| 21 | + end |
| 22 | + end |
| 23 | + let(:phone_number) { "+818000001234" } |
| 24 | + let(:hashed_phone_number) { Digest::SHA256.hexdigest(phone_number) } |
| 25 | + let(:x_line_delivery_tag) { 'd41e0ad70dddfeb68f149ad6fc61574b9c5780ab7bcb2fba5517771ffbb2409c' } |
| 26 | + let(:message) do |
| 27 | + { |
| 28 | + type: 'text', |
| 29 | + text: 'Hello, world' |
| 30 | + } |
| 31 | + end |
| 32 | + |
| 33 | + context 'normal scenario' do |
| 34 | + it 'pushes the message' do |
| 35 | + response = client.push_pnp(hashed_phone_number, message) |
| 36 | + |
| 37 | + expect(response).to be_a(Net::HTTPOK) |
| 38 | + expect(response.body).to eq('{}') |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + context 'with X-Line-Delivery-Tag header' do |
| 43 | + it 'pushes the message with additional header' do |
| 44 | + response = client.push_pnp(hashed_phone_number, message, headers: { 'X-Line-Delivery-Tag' => x_line_delivery_tag }) |
| 45 | + |
| 46 | + expect(response).to be_a(Net::HTTPOK) |
| 47 | + expect(response.body).to eq('{}') |
| 48 | + end |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + describe '#get_message_delivery_pnp' do |
| 53 | + before do |
| 54 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/delivery/pnp?date={date}' |
| 55 | + stub_request(:get, uri_template).to_return { |request| { body: DELIVERY_RESULT_CONTENT, status: 200 } } |
| 56 | + end |
| 57 | + |
| 58 | + let(:client) do |
| 59 | + Line::Bot::Client.new do |config| |
| 60 | + config.channel_token = 'channel_token' |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + it 'gets the delivery result' do |
| 65 | + response = client.get_message_delivery_pnp('20240524') |
| 66 | + |
| 67 | + expect(response).to be_a(Net::HTTPOK) |
| 68 | + expect(response.body).to eq(DELIVERY_RESULT_CONTENT) |
| 69 | + end |
| 70 | + end |
| 71 | +end |
0 commit comments