#!perl
use
5.10.0;
use
lib
"$FindBin::Bin/lib"
;
use
lib
"$FindBin::Bin/../lib"
;
eval
{
};
die
"Mock load exception $@"
if
$@;
subtest
'transport success'
=>
sub
{
my
$p
= Net::Pushover->new(
user
=>
'xxxxxxxxxxxxxxx'
,
token
=>
'xxxxxxxxxxxxxxx'
,
_ua
=> Mock::HTTPClient->new(
status
=>
'200 OK'
,
content
=>
'{"status":1,"request":"d5b4d646a8c23ccefcbdb53220930c9b"}'
)
);
my
$res
=
$p
->message(
text
=>
'Test message'
);
ok
$res
;
ok
$res
->{request};
is
$res
->{status}, 1;
};
subtest
'transport error'
=>
sub
{
my
$p
= Net::Pushover->new(
user
=>
'xxxxxxxxxxxxxxx'
,
token
=>
'xxxxxxxxxxxxxxx'
,
_ua
=> Mock::HTTPClient->new(
status
=>
'400 Bad Request'
,
content
=>
'{"token":"invalid","errors":["application token is invalid"],"status":0,"request":"564a7165072d807c1be9d6f13ea8f3c1"}'
)
);
my
$res
=
$p
->message(
text
=>
'Test message'
);
ok
$res
;
is
$res
->{status}, 0;
is
$res
->{errors}->[0],
'application token is invalid'
;
};
done_testing();