Skip to content

Commit

Permalink
Add warning for responses without HTTP codes, remove Moose dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
n7st committed Jun 10, 2021
1 parent b859d9f commit 891d436
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
5 changes: 2 additions & 3 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ license = MIT
copyright_holder = Mike Jones
copyright_year = 2020

version = 0.24
version = 0.25

[TestRelease]
[UploadToCPAN::WWWPAUSESimple]
Expand All @@ -22,8 +22,7 @@ DateTime = 0
Encode = 0
List::MoreUtils = 0
Mojolicious = 8.57
Moo = 0
Moose = 0
Moo = 2.005004
MooX::HandlesVia = 0
Readonly = 0
Role::EventEmitter = 0
Expand Down
2 changes: 1 addition & 1 deletion lib/WebService/Mattermost.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Types::Standard qw(Bool Int Object Str);

use WebService::Mattermost::V4::API;

our $VERSION = 0.24;
our $VERSION = 0.25;

################################################################################

Expand Down
10 changes: 9 additions & 1 deletion lib/WebService/Mattermost/V4/API/Resource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,22 @@ sub _as_response {
$view_name = $args->{view};
}

unless ($res->code) {
$self->logger->warn('No HTTP code was received from Mattermost. Is your server alive?');

if ($res->message) {
$self->logger->warnf('The following may be useful: %s', $res->message);
}
}

if ($res->is_error && $self->debug) {
$self->logger->warnf('An API error occurred: %s', $res->message);
}

return WebService::Mattermost::V4::API::Response->new({
auth_token => $self->auth_token,
base_url => $self->base_url,
code => $res->code,
code => $res->code || 0,
headers => $res->headers,
is_error => $res->is_error ? 1 : 0,
is_success => $res->is_success ? 1 : 0,
Expand Down
27 changes: 14 additions & 13 deletions t/unit/WebService/Mattermost/V4/API/Role/RequireID.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env perl -t
#!/usr/bin/env perl -T

use Moose::Util 'apply_all_roles';
use Test::Exception;
use Test::Spec;

package EmptyRequireIDConsumer { use Moose; };
package EmptyRequireIDConsumer { use Moo; };

package RequireIDConsumer {
use Moose;
use Moo;

with qw(
WebService::Mattermost::Role::Returns
Expand All @@ -20,40 +19,42 @@ package RequireIDConsumer {

return 1;
}

1;
};

describe 'WebService::Mattermost::V4::API::Role::RequireID' => sub {
share my %vars;

before each => sub {
$vars{app} = RequireIDConsumer->new();
};

describe 'role validation' => sub {
before each => sub { $vars{app} = EmptyRequireIDConsumer->new(); };

context 'with the required additional role' => sub {
it 'should not throw a missing method error' => sub {
lives_ok {
apply_all_roles($vars{app}, qw(
Moo::Role->apply_roles_to_package('RequireIDConsumer', qw(
WebService::Mattermost::Role::Returns
WebService::Mattermost::V4::API::Role::RequireID
));

RequireIDConsumer->new();
};
};
};

context 'without the required additional role' => sub {
it 'should throw a missing method error' => sub {
throws_ok {
apply_all_roles($vars{app},
Moo::Role->apply_roles_to_package('EmptyRequireIDConsumer',
'WebService::Mattermost::V4::API::Role::RequireID');
} qr{requires the method 'error_return'};

EmptyRequireIDConsumer->new();
} qr{missing error_return};
};
};
};

describe '#validate_id' => sub {
before each => sub { $vars{app} = RequireIDConsumer->new(); };

context 'with a valid UUID' => sub {
it 'run the next method in the chain' => sub {
my $id = '18abe71f-ab63-4dbf-bd01-6aa60e7bb396';
Expand Down

0 comments on commit 891d436

Please sign in to comment.