summary refs log tree commit diff
path: root/t/01_basic.t
blob: e52f0e1af2f8f81da4ce54585b37424cf8b3ab5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use strict;
use warnings;
use Test::More;
use Test::Exception;
use lib ('t/lib');
use FakeAPI;

my $obj = FakeAPI->new;
ok $obj, "... object created";
ok $obj->meta->has_attribute('api_useragent'),
    "... useragent attribute have been added";

ok my $method = $obj->meta->find_method_by_name('get_user'),
    '... method get_user have been created';

ok $method->meta->has_attribute('path'), '... method bar have attribute path';
is $method->path, '/user/$id', '... get good path value';

ok my @methods = $obj->meta->local_api_methods(), '... get api methods';
is scalar @methods, 6, '... get 6 methods in our API';

ok my $users = $obj->users(), "... get users list";
is $users->{status}, 1, "... get users";

ok my $user = $obj->get_user( id => 1 ), "... fetch user";
is $user->{status}, 1, "... get bruce wayne";

ok my ($user, $http_response) = $obj->get_user(id => 1), "... fetch user";
isa_ok $http_response, "HTTP::Response", "... got the HTTP response object";

#dies_ok { $obj->get_user( id => 12 ) } "... can't fetch unknown user";
#my $err = $@;
#is $err->http_code, 404, "... get 404";

#my $auth_obj = FakeAPI->new();
#my $res = $auth_obj->auth_get_user(id => 1);

done_testing;