Skip to content

Commit f6cfa10

Browse files
authored
Add test for get followers (#441)
To verify the behavior, this change adds several tests for get followers API. Optional parameters are ignored if not specified. Additionally, the encoding of query parameters is also tested.
1 parent e9546ae commit f6cfa10

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

spec/line/bot/v2/misc_spec.rb

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
.with(
4444
body: "{\"description\":\"Test Audience\"}",
4545
headers: {
46-
'Authorization'=>"Bearer #{channel_access_token}",
47-
'Content-Type'=>'application/json',
46+
'Authorization' => "Bearer #{channel_access_token}",
47+
'Content-Type' => 'application/json',
4848
}
4949
)
5050
.to_return(status: 202, body: "{\"description\": \"Test Audience response\"}", headers: {})
@@ -231,7 +231,7 @@
231231
it "doesn't require bearer token" do
232232
stub_request(:post, "https://api.line.me/v2/oauth/accessToken")
233233
.with(
234-
body: {"clientId"=>"test-client-id", "clientSecret"=>"test-client-secret", "grantType"=>"client_credentials" }
234+
body: { "clientId" => "test-client-id", "clientSecret" => "test-client-secret", "grantType" => "client_credentials" }
235235
)
236236
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
237237

@@ -248,10 +248,10 @@
248248

249249
describe 'GET /v2/bot/followers/ids' do
250250
let(:client) { Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token') }
251-
let(:response_body) { { "user_ids" => ["U1234567890", "U0987654321"] }.to_json }
252251
let(:response_code) { 200 }
253252

254253
it 'returns a list of followers successfully without optional parameters' do
254+
response_body = { "user_ids" => ["U1234567890", "U0987654321"] }.to_json
255255
stub_request(:get, "https://api.line.me/v2/bot/followers/ids")
256256
.with(
257257
headers: {
@@ -265,6 +265,40 @@
265265
expect(status_code).to eq(200)
266266
expect(body.user_ids).to eq(["U1234567890", "U0987654321"])
267267
end
268+
269+
it 'query with only start' do
270+
response_body = { "user_ids" => ["U1234567890", "U0987654321"], "next" => "nExT Token" }.to_json
271+
stub_request(:get, "https://api.line.me/v2/bot/followers/ids?start=from%20previous%20NEXT")
272+
.with(
273+
headers: {
274+
'Authorization' => "Bearer test-channel-access-token"
275+
}
276+
)
277+
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
278+
279+
body, status_code, headers = client.get_followers_with_http_info(start: "from previous NEXT")
280+
281+
expect(status_code).to eq(200)
282+
expect(body.user_ids).to eq(["U1234567890", "U0987654321"])
283+
expect(body._next).to eq("nExT Token")
284+
end
285+
286+
it 'query with limit and start' do
287+
response_body = { "user_ids" => ["U1234567890", "U0987654321"], "next" => "nExT Token" }.to_json
288+
stub_request(:get, "https://api.line.me/v2/bot/followers/ids?limit=10&start=from%20previous%20NEXT")
289+
.with(
290+
headers: {
291+
'Authorization' => "Bearer test-channel-access-token"
292+
}
293+
)
294+
.to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' })
295+
296+
body, status_code, headers = client.get_followers_with_http_info(start: "from previous NEXT", limit: 10)
297+
298+
expect(status_code).to eq(200)
299+
expect(body.user_ids).to eq(["U1234567890", "U0987654321"])
300+
expect(body._next).to eq("nExT Token")
301+
end
268302
end
269303

270304
describe 'PUT /liff/v1/apps/{liffId}' do

0 commit comments

Comments
 (0)