/
auto-cursor.t
57 lines (43 loc) · 1.89 KB
/
auto-cursor.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!perl
use warnings;
use strict;
use Test::More;
use Net::Twitter;
use JSON qw/to_json/;
use HTTP::Response;
my $json_result = to_json({ ids => ['test'], next_cursor => 1 });
sub mock_ua {
my $nt = shift;
$nt->ua->add_handler(request_send => sub {
my $resp = HTTP::Response->new(200);
$resp->content($json_result);
return $resp;
});
}
{
my $nt_with_max_calls_2 = Net::Twitter->new(traits => ['API::REST', AutoCursor => { max_calls => 2 }]);
my $class_for_max_calls_2 = ref $nt_with_max_calls_2;
my $nt_with_max_calls_4 = Net::Twitter->new(traits => ['API::REST', AutoCursor => { max_calls => 4 }]);
my $class_for_max_calls_4 = ref $nt_with_max_calls_4;
my $json_result = to_json({ ids => ['test'], next_cursor => 1 });
mock_ua($_) for $nt_with_max_calls_2, $nt_with_max_calls_4;
my $r = $nt_with_max_calls_2->friends_ids({ cursor => -1 });
is scalar @{$r->{ids}}, 1, 'behavior unmodified with "curosor" arg';
$r = $nt_with_max_calls_2->friends_ids({ -force_cursor => 1 });
is scalar @$r, 2, 'max_calls => 2';
$r = $nt_with_max_calls_4->friends_ids({ -force_cursor => 1 });
is scalar @$r, 4, 'max_calls => 4';
$r = $nt_with_max_calls_4->followers_ids({ -force_cursor => 1, max_calls => 10 });
is scalar @$r, 10, 'max_calls per call override';
my $nt = Net::Twitter->new(traits => ['API::REST', AutoCursor => { max_calls => 2 }]);
mock_ua($nt);
is ref $nt, $class_for_max_calls_2, 'clone max_calls => 2, class name';
$r = $nt->friends_ids({ -force_cursor => 1 });
is scalar @$r, 2, 'cloned max_calls => 2';
$nt = Net::Twitter->new(traits => ['API::REST', AutoCursor => { max_calls => 4 }]);
mock_ua($nt);
is ref $nt, $class_for_max_calls_4, 'clone max_calls => 4, class name';
$r = $nt->friends_ids({ -force_cursor => 1 });
is scalar @$r, 4, 'cloned max_calls => 4';
}
done_testing;