File: search.t

package info (click to toggle)
libpithub-perl 0.01033-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 928 kB
  • ctags: 321
  • sloc: perl: 3,282; makefile: 7
file content (75 lines) | stat: -rw-r--r-- 2,281 bytes parent folder | download | duplicates (2)
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
use FindBin;
use lib "$FindBin::Bin/lib";
use Pithub::Test::Factory;
use Test::Most;

BEGIN {
    use_ok('Pithub::Search');
}

# Pithub::Search->email
{
    my $obj = Pithub::Test::Factory->create('Pithub::Search');

    isa_ok $obj, 'Pithub::Search';

    throws_ok { $obj->email } qr{Missing key in parameters: email}, 'Missing email parameter';

    {
        my $result = $obj->email( email => 'bla' );
        is $result->request->method, 'GET', 'HTTP method';
        is $result->request->uri->path, '/legacy/user/email/bla', 'HTTP path';
    }
}

# Pithub::Search->issues
{
    my $obj = Pithub::Test::Factory->create( 'Pithub::Search', user => 'foo', repo => 'bar' );

    isa_ok $obj, 'Pithub::Search';

    throws_ok { $obj->issues } qr{Missing key in parameters: state}, 'Missing state parameter';
    throws_ok { $obj->issues( state => 'open' ) } qr{Missing key in parameters: keyword}, 'Missing keyword parameter';

    {
        my $result = $obj->issues(
            state   => 'open',
            keyword => 'term',
        );
        is $result->request->method, 'GET', 'HTTP method';
        is $result->request->uri->path, '/legacy/issues/search/foo/bar/open/term', 'HTTP path';
    }
}

# Pithub::Search->repos
{
    my $obj = Pithub::Test::Factory->create('Pithub::Search');

    isa_ok $obj, 'Pithub::Search';

    throws_ok { $obj->repos } qr{Missing key in parameters: keyword}, 'Missing keyword parameter';

    {
        my $result = $obj->repos( keyword => 'bla', params => { language => 'Perl', start_page => '100' } );
        is $result->request->method, 'GET', 'HTTP method';
        is $result->request->uri->path, '/legacy/repos/search/bla', 'HTTP path';
        eq_or_diff { $result->request->uri->query_form }, { language => 'Perl', start_page => '100', per_page => 100 }, 'Query params';
    }
}

# Pithub::Search->users
{
    my $obj = Pithub::Test::Factory->create('Pithub::Search');

    isa_ok $obj, 'Pithub::Search';

    throws_ok { $obj->users } qr{Missing key in parameters: keyword}, 'Missing keyword parameter';

    {
        my $result = $obj->users( keyword => 'bla' );
        is $result->request->method, 'GET', 'HTTP method';
        is $result->request->uri->path, '/legacy/user/search/bla', 'HTTP path';
    }
}

done_testing;