App-GitHubWebhooks2Ikachan

 view release on metacpan or  search on metacpan

t/01_issues.t  view on Meta::CPAN

#!perl

use strict;
use warnings;
use utf8;
use Capture::Tiny qw/capture capture_stderr/;
use File::Spec::Functions qw/catfile/;
use FindBin;
use Hash::MultiValue;
use Plack::Request;

use App::GitHubWebhooks2Ikachan;

use Test::More;

my $g2i = App::GitHubWebhooks2Ikachan->new({

t/01_issues.t  view on Meta::CPAN

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "issues",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
            subscribe => 'issues',
            issues    => 'opened',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!\[INFO\] POST $channel, \00303\[issue opened \(#13\)\] This is new issue \(\@moznion\)\17 https://github.com/moznion/sandbox/issues/13!;
};

subtest 'issue closed' => sub {
    open my $fh, '<', catfile($FindBin::Bin, 'resources', 'issues', 'closed.json');
    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "issues",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
            subscribe => 'issues',
            issues    => 'closed',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!\[INFO\] POST $channel, \00303\[issue closed \(#13\)\] This is new issue \(\@moznion\)\17 https://github.com/moznion/sandbox/issues/13!;
};

subtest 'issue reopened' => sub {
    open my $fh, '<', catfile($FindBin::Bin, 'resources', 'issues', 'reopened.json');
    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "issues",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
            subscribe => 'issues',
            issues    => 'reopened',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!\[INFO\] POST $channel, \00303\[issue reopened \(#13\)\] This is new issue \(\@moznion\)\17 https://github.com/moznion/sandbox/issues/13!;
};

subtest 'subscribe all actions' => sub {
    open my $fh, '<', catfile($FindBin::Bin, 'resources', 'issues', 'opened.json');
    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "issues",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
            subscribe => 'issues',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!\[INFO\] POST $channel, \00303\[issue opened \(#13\)\] This is new issue \(\@moznion\)\17 https://github.com/moznion/sandbox/issues/13!;
};

subtest 'not subscribe action' => sub {
    open my $fh, '<', catfile($FindBin::Bin, 'resources', 'issues', 'opened.json');
    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "issues",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
            subscribe => 'issues',
            issues    => 'close',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    ok !$got;
};

done_testing;

t/02_issue_comment.t  view on Meta::CPAN

#!perl

use strict;
use warnings;
use utf8;
use Capture::Tiny qw/capture capture_stderr/;
use File::Spec::Functions qw/catfile/;
use FindBin;
use Hash::MultiValue;
use Plack::Request;

use App::GitHubWebhooks2Ikachan;

use Test::More;

my $g2i = App::GitHubWebhooks2Ikachan->new({

t/02_issue_comment.t  view on Meta::CPAN


    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "issue_comment",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
            subscribe => 'issue_comment',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!POST $channel, \00303\[comment \(#13\)\] foobar \(\@moznion\)\17 https://github\.com/moznion/sandbox/issues/13#issuecomment-37093289!;
};

done_testing;

t/03_pull_request.t  view on Meta::CPAN

#!perl

use strict;
use warnings;
use utf8;
use Capture::Tiny qw/capture capture_stderr/;
use File::Spec::Functions qw/catfile/;
use FindBin;
use Hash::MultiValue;
use Plack::Request;

use App::GitHubWebhooks2Ikachan;

use Test::More;

my $g2i = App::GitHubWebhooks2Ikachan->new({

t/03_pull_request.t  view on Meta::CPAN

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "pull_request",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload      => $payload,
            subscribe    => 'pull_request',
            pull_request => 'opened',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!\[INFO\] POST $channel, \00303\[pull request opened \(#15\)\] New Pull Request \(\@moznion\)\17 https://github.com/moznion/sandbox/pull/15!;
};

subtest 'pull request closed' => sub {
    open my $fh, '<', catfile($FindBin::Bin, 'resources', 'pull_request', 'closed.json');
    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "pull_request",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload      => $payload,
            subscribe    => 'pull_request',
            pull_request => 'closed',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!\[INFO\] POST $channel, \00303\[pull request closed \(#15\)\] New Pull Request \(\@moznion\)\17 https://github.com/moznion/sandbox/pull/15!;
};

subtest 'issue reopened' => sub {
    open my $fh, '<', catfile($FindBin::Bin, 'resources', 'pull_request', 'reopened.json');
    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "pull_request",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload      => $payload,
            subscribe    => 'pull_request',
            pull_request => 'reopened',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!\[INFO\] POST $channel, \00303\[pull request reopened \(#15\)\] New Pull Request \(\@moznion\)\17 https://github.com/moznion/sandbox/pull/15!;
};

subtest 'issue synchronize' => sub {
    open my $fh, '<', catfile($FindBin::Bin, 'resources', 'pull_request', 'synchronize.json');
    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "pull_request",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload      => $payload,
            subscribe    => 'pull_request',
            pull_request => 'synchronize',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!\[INFO\] POST $channel, \00303\[pull request synchronize \(#15\)\] New Pull Request \(\@moznion\)\17 https://github.com/moznion/sandbox/pull/15!;
};

subtest 'subscribe all actions' => sub {
    open my $fh, '<', catfile($FindBin::Bin, 'resources', 'pull_request', 'opened.json');
    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "pull_request",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!\[INFO\] POST $channel, \00303\[pull request opened \(#15\)\] New Pull Request \(\@moznion\)\17 https://github.com/moznion/sandbox/pull/15!;
};

subtest 'not subscribe action' => sub {
    open my $fh, '<', catfile($FindBin::Bin, 'resources', 'pull_request', 'opened.json');
    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "pull_request",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload      => $payload,
            subscribe    => 'pull_request',
            pull_request => 'close',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    ok !$got;
};

done_testing;

t/04_push.t  view on Meta::CPAN

#!perl

use strict;
use warnings;
use utf8;
use Capture::Tiny qw/capture capture_stderr/;
use File::Spec::Functions qw/catfile/;
use FindBin;
use Hash::MultiValue;
use Plack::Request;

use App::GitHubWebhooks2Ikachan;

use Test::More;

my $g2i = App::GitHubWebhooks2Ikachan->new({

t/04_push.t  view on Meta::CPAN


    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "push",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
            subscribe => 'push',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    my @commits = split /\n/, $got;

    like $commits[0], qr!POST $channel, \00303\[push to master\] Commit1 \(\@moznion\)\17 https://github\.com/moznion/sandbox/commit/b4da12df1bc19d2b20d7ab8a11fe9a4413ddf509!;
    like $commits[1], qr!POST $channel, \00303\[push to master\] Commit2 \(\@moznion\)\17 https://github\.com/moznion/sandbox/commit/e2e64cea713dbfb574f1ace80a4be6c55f98433d!;
};

subtest 'merge commit' => sub {
    open my $fh, '<', catfile($FindBin::Bin, 'resources', 'push', 'merge.json');
    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "push",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
            subscribe => 'push',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!POST $channel, \00303\[push to master\] Merge pull request #15 from moznion/new_pull_request \(\@moznion\)\17 https://github\.com/moznion/sandbox/commit/d2427a9b4ffbf5277cfe4229f22b0337146b77d3!;
};

done_testing;

t/05_commit_comment.t  view on Meta::CPAN

#!perl

use strict;
use warnings;
use utf8;
use Capture::Tiny qw/capture_stderr/;
use File::Spec::Functions qw/catfile/;
use FindBin;
use Hash::MultiValue;
use Plack::Request;

use App::GitHubWebhooks2Ikachan;

use Test::More;

my $g2i = App::GitHubWebhooks2Ikachan->new({

t/05_commit_comment.t  view on Meta::CPAN


    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "commit_comment",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
            subscribe => 'commit_comment',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    my @commits = split /\n/, $got;

    like $commits[0], qr%POST foo, \00303\[comment \(adfb4f5\)\] Hello! \(\@moznion\)\17 https://github\.com/moznion/sandbox/commit/adfb4f5fa983e4fc5d5559d6b653284ca03f296d#commitcomment-5920929%;
};

done_testing;

t/06_review_comment.t  view on Meta::CPAN

#!perl

use strict;
use warnings;
use utf8;
use Capture::Tiny qw/capture_stderr/;
use File::Spec::Functions qw/catfile/;
use FindBin;
use Hash::MultiValue;
use Plack::Request;

use App::GitHubWebhooks2Ikachan;

use Test::More;

my $g2i = App::GitHubWebhooks2Ikachan->new({

t/06_review_comment.t  view on Meta::CPAN


    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "pull_request_review_comment",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
            subscribe => 'pull_request_review_comment',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    my @commits = split /\n/, $got;

    like $commits[0], qr%POST foo, \00303\[review comment \(#18\)\] Hello \(\@moznion\)\17 https://github\.com/moznion/sandbox/pull/18#discussion_r11326210%;
};

done_testing;

t/10_subscribe.t  view on Meta::CPAN

#!perl

use strict;
use warnings;
use utf8;
use Capture::Tiny qw/capture capture_stderr/;
use File::Spec::Functions qw/catfile/;
use FindBin;
use Hash::MultiValue;
use Plack::Request;

use App::GitHubWebhooks2Ikachan;

use Test::More;

my $g2i = App::GitHubWebhooks2Ikachan->new({

t/10_subscribe.t  view on Meta::CPAN

    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "issues",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    like $got, qr!\[INFO\] POST $channel, \00303\[issue opened \(#13\)\] This is new issue \(\@moznion\)\17 https://github\.com/moznion/sandbox/issues/13!;
};

subtest 'not subscribe event' => sub {
    open my $fh, '<', catfile($FindBin::Bin, 'resources', 'issues', 'opened.json');
    my $payload = do { local $/; <$fh>; };

    my $req = Plack::Request->new({
        HTTP_X_GITHUB_EVENT => "issues",
        PATH_INFO => "/$channel",
        'plack.request.body' => Hash::MultiValue->new(
            payload   => $payload,
            subscribe => 'push',
        ),
    });

    my $got = capture_stderr{ $g2i->respond_to_ikachan($req) };
    ok !$got;
};

done_testing;



( run in 0.838 second using v1.01-cache-2.11-cpan-26ccb49234f )