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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
use FindBin;
use lib "$FindBin::Bin/lib";
use Pithub::Test;
use Test::Most;
BEGIN {
use_ok('Pithub::Events');
}
{
my $obj = Pithub::Test->create( 'Pithub::Events', user => 'foo', repo => 'bar' );
isa_ok $obj, 'Pithub::Events';
throws_ok { $obj->org_for_user( user => 'foo', org => 'bar' ) } qr{Access token required for: GET /users/foo/events/orgs/bar\s+}, 'Token required';
ok $obj->token(123), 'Token set';
throws_ok { $obj->org } qr{Missing key in parameters: org}, 'No parameters';
throws_ok { $obj->org_for_user } qr{Missing key in parameters: org}, 'No parameters';
throws_ok { $obj->org_for_user( org => 'foo' ) } qr{Missing key in parameters: user}, 'No parameters';
throws_ok { $obj->user_performed } qr{Missing key in parameters: user}, 'No parameters';
throws_ok { $obj->user_received } qr{Missing key in parameters: user}, 'No parameters';
my @tests = (
{
method => 'issue',
path => '/repos/foo/bar/issues/events',
},
{
method => 'network',
path => '/networks/foo/bar/events',
},
{
method => 'public',
path => '/events',
},
{
method => 'repos',
path => '/repos/foo/bar/events',
},
{
method => 'org',
params => [ org => 'some-org' ],
path => '/orgs/some-org/events',
},
{
method => 'org_for_user',
params => [ org => 'some-org', user => 'some-user' ],
path => '/users/some-user/events/orgs/some-org',
},
{
method => 'user_performed',
params => [ user => 'some-user' ],
path => '/users/some-user/events',
},
{
method => 'user_received',
params => [ user => 'some-user' ],
path => '/users/some-user/received_events',
},
);
foreach my $test (@tests) {
my $method = $test->{method};
my $path = $test->{path};
my @params = @{ $test->{params} || [] };
my $result = $obj->$method(@params);
is $result->request->method, 'GET', 'HTTP method';
is $result->request->uri->path, $path, 'HTTP path';
is $result->request->content, '', 'HTTP body';
}
is $obj->user_performed( user => 'foo', public => 1 )->request->uri->path, '/users/foo/events/public', 'HTTP path';
is $obj->user_received( user => 'foo', public => 1 )->request->uri->path, '/users/foo/received_events/public', 'HTTP path';
}
done_testing;
|