File: search.t

package info (click to toggle)
libpithub-perl 0.01043-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,148 kB
  • sloc: perl: 9,098; makefile: 7
file content (95 lines) | stat: -rwxr-xr-x 2,553 bytes parent folder | download
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!perl

use strict;
use warnings;

use Test::Differences qw( eq_or_diff );
use Test::Exception;    # throws_ok
use Test::More import => [qw( done_testing is isa_ok )];

use lib 't/lib';
use Pithub::Search        ();
use Pithub::Test::Factory ();

# 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;