2323}
2424EOS
2525
26+ LIMITED_USER_ID_CONTENT = <<"EOS"
27+ {
28+ "userIds": [
29+ "Uxxxxxxxxxxxxxx1",
30+ "Uxxxxxxxxxxxxxx2"
31+ ]
32+ }
33+ EOS
34+
2635describe Line ::Bot ::Client do
2736 def dummy_config
2837 {
@@ -42,7 +51,7 @@ def generate_client
4251 uri_template = Addressable ::Template . new Line ::Bot ::API ::DEFAULT_ENDPOINT + '/bot/followers/ids'
4352 stub_request ( :get , uri_template ) . to_return { |request | { body : USER_ID_CONTENT , status : 200 } }
4453
45- uri_template = Addressable ::Template . new Line ::Bot ::API ::DEFAULT_ENDPOINT + '/bot/followers/ids?start={continuationToken }'
54+ uri_template = Addressable ::Template . new Line ::Bot ::API ::DEFAULT_ENDPOINT + '/bot/followers/ids?start={start }'
4655 stub_request ( :get , uri_template ) . to_return { |request | { body : NEXT_USER_ID_CONTENT , status : 200 } }
4756
4857 client = generate_client
@@ -56,11 +65,35 @@ def generate_client
5665 expect ( result [ 'next' ] ) . to eq "jxEWCEEP"
5766
5867 # second page
59- response = client . get_follower_ids ( result [ 'next' ] )
68+ response = client . get_follower_ids ( start : result [ 'next' ] )
6069
6170 expect ( response ) . to be_a ( Net ::HTTPOK )
6271 result = JSON . parse ( response . body )
6372 expect ( result [ 'userIds' ] ) . to eq [ "Uxxxxxxxxxxxxxx4" , "Uxxxxxxxxxxxxxx5" , "Uxxxxxxxxxxxxxx6" ]
6473 expect ( result [ 'next' ] ) . to be nil
6574 end
75+
76+ it 'gets limited number of follower ids' do
77+ # without any other conditions
78+ uri_template = Addressable ::Template . new Line ::Bot ::API ::DEFAULT_ENDPOINT + '/bot/followers/ids?limit={limit}'
79+ stub_request ( :get , uri_template ) . to_return { |request | { body : LIMITED_USER_ID_CONTENT , status : 200 } }
80+
81+ # with other conditions
82+ uri_template = Addressable ::Template . new Line ::Bot ::API ::DEFAULT_ENDPOINT + '/bot/followers/ids?limit={limit}&start={start}'
83+ stub_request ( :get , uri_template ) . to_return { |request | { body : LIMITED_USER_ID_CONTENT , status : 200 } }
84+
85+ client = generate_client
86+
87+ # without any other conditions
88+ response = client . get_follower_ids ( limit : 2 )
89+ result = JSON . parse ( response . body )
90+ expect ( response ) . to be_a ( Net ::HTTPOK )
91+ expect ( result [ 'userIds' ] ) . to eq [ "Uxxxxxxxxxxxxxx1" , "Uxxxxxxxxxxxxxx2" ]
92+
93+ # with other conditions
94+ response = client . get_follower_ids ( start : 'foo' , limit : 2 )
95+ result = JSON . parse ( response . body )
96+ expect ( response ) . to be_a ( Net ::HTTPOK )
97+ expect ( result [ 'userIds' ] ) . to eq [ "Uxxxxxxxxxxxxxx1" , "Uxxxxxxxxxxxxxx2" ]
98+ end
6699end
0 commit comments