|
| 1 | +require 'spec_helper' |
| 2 | +require 'webmock/rspec' |
| 3 | +require 'json' |
| 4 | + |
| 5 | +USER_ID_CONTENT = <<"EOS" |
| 6 | +{ |
| 7 | + "userIds": [ |
| 8 | + "Uxxxxxxxxxxxxxx1", |
| 9 | + "Uxxxxxxxxxxxxxx2", |
| 10 | + "Uxxxxxxxxxxxxxx3" |
| 11 | + ], |
| 12 | + "next": "jxEWCEEP" |
| 13 | +} |
| 14 | +EOS |
| 15 | + |
| 16 | +NEXT_USER_ID_CONTENT = <<"EOS" |
| 17 | +{ |
| 18 | + "userIds": [ |
| 19 | + "Uxxxxxxxxxxxxxx4", |
| 20 | + "Uxxxxxxxxxxxxxx5", |
| 21 | + "Uxxxxxxxxxxxxxx6" |
| 22 | + ] |
| 23 | +} |
| 24 | +EOS |
| 25 | + |
| 26 | +describe Line::Bot::Client do |
| 27 | + def dummy_config |
| 28 | + { |
| 29 | + channel_token: 'access token', |
| 30 | + } |
| 31 | + end |
| 32 | + |
| 33 | + def generate_client |
| 34 | + client = Line::Bot::Client.new do |config| |
| 35 | + config.channel_token = dummy_config[:channel_token] |
| 36 | + end |
| 37 | + |
| 38 | + client |
| 39 | + end |
| 40 | + |
| 41 | + it 'gets follower ids' do |
| 42 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/followers/ids' |
| 43 | + stub_request(:get, uri_template).to_return { |request| {body: USER_ID_CONTENT, status: 200} } |
| 44 | + |
| 45 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/followers/ids?start={continuationToken}' |
| 46 | + stub_request(:get, uri_template).to_return { |request| {body: NEXT_USER_ID_CONTENT, status: 200} } |
| 47 | + |
| 48 | + client = generate_client |
| 49 | + |
| 50 | + # first page |
| 51 | + response = client.get_follower_ids |
| 52 | + |
| 53 | + expect(response).to be_a(Net::HTTPOK) |
| 54 | + result = JSON.parse(response.body) |
| 55 | + expect(result['userIds']).to eq ["Uxxxxxxxxxxxxxx1", "Uxxxxxxxxxxxxxx2", "Uxxxxxxxxxxxxxx3"] |
| 56 | + expect(result['next']).to eq "jxEWCEEP" |
| 57 | + |
| 58 | + # second page |
| 59 | + response = client.get_follower_ids(result['next']) |
| 60 | + |
| 61 | + expect(response).to be_a(Net::HTTPOK) |
| 62 | + result = JSON.parse(response.body) |
| 63 | + expect(result['userIds']).to eq ["Uxxxxxxxxxxxxxx4", "Uxxxxxxxxxxxxxx5", "Uxxxxxxxxxxxxxx6"] |
| 64 | + expect(result['next']).to be nil |
| 65 | + end |
| 66 | +end |
0 commit comments