Pithub

 view release on metacpan or  search on metacpan

t/pull_requests.t  view on Meta::CPAN

#!perl

use strict;
use warnings;

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

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

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

    throws_ok { $obj->commits }
    qr{Missing key in parameters: pull_request_id}, 'No parameters';

    isa_ok $obj, 'Pithub::PullRequests';

    {
        my $result = $obj->commits( pull_request_id => 1 );
        is $result->request->method, 'GET', 'HTTP method';
        is $result->request->uri->path, '/repos/foo/bar/pulls/1/commits',
            'HTTP path';
        my $http_request = $result->request;
        is $http_request->content, q{}, 'HTTP body';
    }
}

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

    isa_ok $obj, 'Pithub::PullRequests';

    throws_ok { $obj->create }
    qr{Missing key in parameters: data \(hashref\)}, 'No data parameter';
    throws_ok { $obj->create( data => { foo => 'bar' } ); }
    qr{Access token required for: POST /repos/foo/bar/pulls},
        'Token required';

    ok $obj->token(123), 'Token set';

    {
        my $json   = JSON->new;
        my $result = $obj->create(
            data => {
                base  => 'master',
                body  => 'Please pull this in!',
                head  => 'octocat:new-feature',
                title => 'Amazing new feature',
            }
        );
        is $result->request->method,    'POST',                 'HTTP method';
        is $result->request->uri->path, '/repos/foo/bar/pulls', 'HTTP path';
        my $http_request = $result->request;
        eq_or_diff $json->decode( $http_request->content ),
            {



( run in 3.169 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )