23
23
}
24
24
EOS
25
25
26
+ LIMITED_USER_ID_CONTENT = <<"EOS"
27
+ {
28
+ "userIds": [
29
+ "Uxxxxxxxxxxxxxx1",
30
+ "Uxxxxxxxxxxxxxx2"
31
+ ]
32
+ }
33
+ EOS
34
+
26
35
describe Line ::Bot ::Client do
27
36
def dummy_config
28
37
{
@@ -42,7 +51,57 @@ def generate_client
42
51
uri_template = Addressable ::Template . new Line ::Bot ::API ::DEFAULT_ENDPOINT + '/bot/followers/ids'
43
52
stub_request ( :get , uri_template ) . to_return { |request | { body : USER_ID_CONTENT , status : 200 } }
44
53
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}'
55
+ stub_request ( :get , uri_template ) . to_return { |request | { body : NEXT_USER_ID_CONTENT , status : 200 } }
56
+
57
+ client = generate_client
58
+
59
+ # first page
60
+ response = client . get_follower_ids
61
+
62
+ expect ( response ) . to be_a ( Net ::HTTPOK )
63
+ result = JSON . parse ( response . body )
64
+ expect ( result [ 'userIds' ] ) . to eq [ "Uxxxxxxxxxxxxxx1" , "Uxxxxxxxxxxxxxx2" , "Uxxxxxxxxxxxxxx3" ]
65
+ expect ( result [ 'next' ] ) . to eq "jxEWCEEP"
66
+
67
+ # second page
68
+ response = client . get_follower_ids ( start : result [ 'next' ] )
69
+
70
+ expect ( response ) . to be_a ( Net ::HTTPOK )
71
+ result = JSON . parse ( response . body )
72
+ expect ( result [ 'userIds' ] ) . to eq [ "Uxxxxxxxxxxxxxx4" , "Uxxxxxxxxxxxxxx5" , "Uxxxxxxxxxxxxxx6" ]
73
+ expect ( result [ 'next' ] ) . to be nil
74
+ 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
99
+
100
+ it 'gets follower ids using deprecated_continuation_token argument' do
101
+ uri_template = Addressable ::Template . new Line ::Bot ::API ::DEFAULT_ENDPOINT + '/bot/followers/ids'
102
+ stub_request ( :get , uri_template ) . to_return { |request | { body : USER_ID_CONTENT , status : 200 } }
103
+
104
+ uri_template = Addressable ::Template . new Line ::Bot ::API ::DEFAULT_ENDPOINT + '/bot/followers/ids?start={start}'
46
105
stub_request ( :get , uri_template ) . to_return { |request | { body : NEXT_USER_ID_CONTENT , status : 200 } }
47
106
48
107
client = generate_client
0 commit comments