Google-Plus
view release on metacpan or search on metacpan
t/01-plus.t view on Meta::CPAN
#!/usr/bin/env perl
use Test::Most;
use Net::Ping;
BEGIN {
plan skip_all => 'these tests are not for smoke testing'
if $ENV{AUTOMATED_TESTING};
plan skip_all => 'Needs Google+ API key in %ENV'
unless $ENV{GOOGLE_PLUS_API_KEY};
my $p = Net::Ping->new('syn', 2);
$p->port_number(scalar getservbyname(https => 'tcp'));
$p->service_check(1);
plan skip_all => 'Needs access to remote Google API endpoint'
unless $p->ping('www.googleapis.com');
plan tests => 4;
}
use Google::Plus;
# Google+Zak
my $user_id = '112708775709583792684';
my $g;
subtest 'create object' => sub {
plan tests => 5;
can_ok 'Google::Plus' => 'new';
throws_ok { Google::Plus->new } qr/key.+required/, 'needs API key';
throws_ok { Google::Plus->new(blah => 'ther') } qr/key.+required/,
'bad key';
$g = new_ok 'Google::Plus', [key => $ENV{GOOGLE_PLUS_API_KEY}];
ok ref $g => 'Made object';
};
my $person;
subtest 'get person profile' => sub {
plan tests => 7;
can_ok $g => 'person';
throws_ok { $g->person } qr/ID.+required/, 'needs user ID';
throws_ok { $g->person('foo') } qr/Invalid/, 'user ID must be numeric';
throws_ok { $g->person('00000000000000000000') } qr/unable to map/,
'bad person';
$person = $g->person($user_id);
isa_ok $person => 'HASH';
subtest 'person properties' => sub {
plan tests => 10;
ok $person->{$_}, "$_ exists"
for qw/ aboutMe displayName gender id image organizations placesLived
tagline url urls /;
};
subtest 'person profile partial response' => sub {
plan tests => 6;
my @fields = qw(displayName gender aboutMe);
my $partial = $g->person($user_id, join ',' => @fields);
isa_ok $partial => 'HASH', 'got partial response for person';
ok $partial->{$_}, "$_ exists in partial response" for @fields;
ok !exists $partial->{birthday}, "birthday should not be in response";
throws_ok { $g->person($user_id, 'invalid,fields') } qr/Invalid field/,
"partial response using invalid field names";
};
( run in 0.704 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )