Dist-Zilla-PluginBundle-Codeberg

 view release on metacpan or  search on metacpan

t/tests/dist/zilla/plugin/codeberg/create.t  view on Meta::CPAN

use Modern::Perl;
use Test2::V1 -ipP;
use Test2::Tools::Compare qw/hash array bag item match end/;
use Test2::Tools::Explain;
use Test2::Tools::JSON;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Path::Tiny;
use Storable qw(dclone);
use Test::DZil;

use Dist::Zilla::Plugin::Codeberg;
my $mock_dist_zilla_plugin_codeberg
   = mock 'Dist::Zilla::Plugin::Codeberg' => (
   override => [
      _build_credentials =>
         sub { return { login => 'bob', token => 'AbC00ToKeN' } },
   ],
   );

my @http_requests;

use HTTP::Tiny;
my $mock_http_tiny = mock 'HTTP::Tiny' => (
   override => [
      request => sub {
         my $self = shift;

         # keep a snapshot: the plugin reuses the same headers hashref
         # across calls, mutating it after this one is captured
         push @http_requests, dclone( [@_] );

         my ( $method, $url ) = @_;
         if ( $url =~ m{/namespaces$} ) {
            return {
               success => 1,
               content => '[{"id":42,"path":"myteam"}]',
            };
         }
         return {
            success => 1,
            content => '{"ssh_url":"git@codeberg.org:bob/My-Stuff.git"}',
         };
      }
   ]
);

my $auth_headers = { 'Authorization' => 'token AbC00ToKeN' };

my @tests = (
   {
      test_name    => 'default config creates a public repo',
      config       => {},
      mint_opts    => {},
      log_messages => [
         q/[Codeberg::Create] Creating new Codeberg repository 'DZT-Sample'/,
         '[Codeberg::Create] Issues are enabled',
         '[Codeberg::Create] Wiki is enabled',
         '[Codeberg::Create] Packages are enabled',
         '[Codeberg::Create] Snippets are enabled',
         '[Codeberg::Create] Merge requests are enabled',
         '[Codeberg::Create] Sending POST https://codeberg.org/api/v1/user/repos',
      ],
      expected_requests => [
         [
            'POST',
            'https://codeberg.org/api/v1/user/repos',
            {
               headers =>
                  { %$auth_headers, 'content-type' => 'application/json' },
               content => json(
                  {
                     name                   => 'DZT-Sample',
                     visibility             => 'public',
                     description            => undef,
                     issues_enabled         => 1,



( run in 1.217 second using v1.01-cache-2.11-cpan-007c89162af )