|
131 | 131 | end |
132 | 132 | end |
133 | 133 |
|
| 134 | + describe 'GET /v2/bot/insight/followers' do |
| 135 | + let(:client) { Line::Bot::V2::Insight::ApiClient.new(channel_access_token: channel_access_token) } |
| 136 | + let(:response_code) { 200 } |
| 137 | + |
| 138 | + it 'returns the number of followers successfully (ready status)' do |
| 139 | + response_body = { |
| 140 | + "status" => "ready", |
| 141 | + "followers" => 1000, |
| 142 | + "targetedReaches" => 900, |
| 143 | + "blocks" => 100 |
| 144 | + }.to_json |
| 145 | + |
| 146 | + stub_request(:get, "https://api.line.me/v2/bot/insight/followers") |
| 147 | + .with( |
| 148 | + headers: { |
| 149 | + 'Authorization' => "Bearer #{channel_access_token}" |
| 150 | + } |
| 151 | + ) |
| 152 | + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
| 153 | + |
| 154 | + body, status_code, = client.get_number_of_followers_with_http_info |
| 155 | + |
| 156 | + expect(status_code).to eq(200) |
| 157 | + expect(body.status).to eq('ready') |
| 158 | + expect(body.followers).to eq(1000) |
| 159 | + expect(body.targeted_reaches).to eq(900) |
| 160 | + expect(body.blocks).to eq(100) |
| 161 | + end |
| 162 | + |
| 163 | + it 'handles the null fields properly (unready status)' do |
| 164 | + response_body = { |
| 165 | + "status" => "unready", |
| 166 | + "followers" => nil, |
| 167 | + "targetedReaches" => nil, |
| 168 | + "blocks" => nil |
| 169 | + }.to_json |
| 170 | + |
| 171 | + stub_request(:get, "https://api.line.me/v2/bot/insight/followers") |
| 172 | + .with( |
| 173 | + headers: { |
| 174 | + 'Authorization' => "Bearer #{channel_access_token}" |
| 175 | + } |
| 176 | + ) |
| 177 | + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
| 178 | + |
| 179 | + body, status_code, = client.get_number_of_followers_with_http_info |
| 180 | + |
| 181 | + expect(status_code).to eq(200) |
| 182 | + expect(body.status).to eq('unready') |
| 183 | + expect(body.followers).to be_nil |
| 184 | + expect(body.targeted_reaches).to be_nil |
| 185 | + expect(body.blocks).to be_nil |
| 186 | + end |
| 187 | + end |
| 188 | + |
| 189 | + describe 'GET /v2/bot/message/progress/narrowcast' do |
| 190 | + let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: channel_access_token) } |
| 191 | + let(:response_body) do |
| 192 | + # missing errorCode, completedTime, targetCount |
| 193 | + { |
| 194 | + "phase" => "waiting", |
| 195 | + "acceptedTime" => "2020-12-03T10:15:30.121Z" |
| 196 | + } |
| 197 | + .to_json |
| 198 | + end |
| 199 | + let(:response_code) { 200 } |
| 200 | + |
| 201 | + it 'no problem even when response does not contain some JSON keys' do |
| 202 | + stub_request(:get, "https://api.line.me/v2/bot/message/progress/narrowcast?requestId=7d51557c-7ba0-4ed7-991f-36b2a340dc1a") |
| 203 | + .with( |
| 204 | + headers: { |
| 205 | + 'Authorization'=>'Bearer YOUR_CHANNEL_ACCESS_TOKEN', |
| 206 | + } |
| 207 | + ) |
| 208 | + .to_return(status: response_code, body: response_body, headers: { 'x-line-request-id' => '3a785346-2cf3-482f-8469-c893117fcef8' }) |
| 209 | + |
| 210 | + body, status_code, headers = client.get_narrowcast_progress_with_http_info( |
| 211 | + request_id: '7d51557c-7ba0-4ed7-991f-36b2a340dc1a' |
| 212 | + ) |
| 213 | + |
| 214 | + expect(status_code).to eq(200) |
| 215 | + expect(body.phase).to eq('waiting') |
| 216 | + expect(body.accepted_time).to eq('2020-12-03T10:15:30.121Z') |
| 217 | + expect(body.error_code).to be_nil |
| 218 | + expect(body.completed_time).to be_nil |
| 219 | + expect(body.target_count).to be_nil |
| 220 | + end |
| 221 | + end |
| 222 | + |
134 | 223 | describe 'POST /v2/oauth/accessToken' do |
135 | 224 | let(:client) { Line::Bot::V2::ChannelAccessToken::ApiClient.new } |
136 | 225 | let(:grant_type) { 'client_credentials' } |
|
0 commit comments