1#!/usr/bin/env perl
2use strict;
3use warnings;
4
5use WebService::Pushover;
6use Test::More;
7use Test::Deep;
8
9BEGIN {
10	plan skip_all => "Integration tests disabled unless both PUSHOVER_API_TOKEN"
11		." and PUSHOVER_USER_TOKEN environment variables are set"
12			unless $ENV{PUSHOVER_API_TOKEN} && $ENV{PUSHOVER_USER_TOKEN};
13}
14
15my $api = WebService::Pushover->new(
16	api_token => $ENV{PUSHOVER_API_TOKEN},
17	user_token => $ENV{PUSHOVER_USER_TOKEN}
18) or BAIL_OUT("Couldn't instantiate the WebService::Pushover object. Testing cannot continue");
19
20my $res = $api->message(message => "Test message");
21cmp_deeply($res, superhashof({ status => 1 }), "Basic message() call succeeded")
22	or diag explain $res;
23
24$res = $api->message(
25	message   => q|test message: abcdefghijklmnopqrstuvwxyz01234567889!@#$%^&*()-=_+`~[]\\{}\|;:'"/?.><|,
26	sound     => "bike",
27	timestamp => 42,
28	priority  => 2,
29	retry     => 30,
30	expire    => 30);
31cmp_deeply($res, superhashof({ status => 1, receipt => re(qr/^\w+$/) }),
32	"Advanced message() call succeeded") or diag explain $res;
33
34$res = $api->receipt(receipt => $res->{receipt});
35cmp_deeply($res, superhashof({ status => 1 }),
36	"receipt() call based on previous high priority message succeeded") or diag explain $res;
37
38$res = $api->user();
39cmp_deeply($res, superhashof({ status => 1 }), "user() call succeeded") or diag explain $res;
40
41$res = $api->sounds();
42cmp_deeply($res, superhashof({ status => 1, sounds => ignore }), "sounds() call succeeded")
43	or diag explain $res;
44
45done_testing;
46