summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2009-12-20 19:55:04 +0100
committerfranck cuny <franck@lumberjaph.net>2009-12-20 19:55:04 +0100
commit57080b2666e528223676bd20d864a4a39f6f7076 (patch)
tree8b67a68c92782d4dae7ac51bac809c4e064133d7
parentChecking in changes prior to tagging of version 0.06. Changelog diff is: (diff)
downloadnet-http-api-57080b2666e528223676bd20d864a4a39f6f7076.tar.gz
start to rewrite tests
-rw-r--r--t/01_basic.t17
-rw-r--r--t/lib/FakeAPI.pm22
2 files changed, 28 insertions, 11 deletions
diff --git a/t/01_basic.t b/t/01_basic.t
index 1ff9faf..92f5d03 100644
--- a/t/01_basic.t
+++ b/t/01_basic.t
@@ -20,17 +20,16 @@ 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->[0]->{user}, "bruce wayne", "... get bruce wayne";
+is $users->{status}, 1, "... get users";
-ok my $user = $obj->get_user( id => $users->[0]->{id} ),
- "... fetch bruce wayne informations";
-is $user->{user}, "bruce wayne", "... get bruce wayne";
+ok my $user = $obj->get_user( id => 1 ), "... fetch user";
+is $user->{status}, 1, "... get bruce wayne";
-dies_ok { $obj->get_user( id => 12 ) } "... can't fetch unknown user";
-my $err = $@;
-is $err->http_code, 404, "... get 404";
+#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);
+#my $auth_obj = FakeAPI->new();
+#my $res = $auth_obj->auth_get_user(id => 1);
done_testing;
diff --git a/t/lib/FakeAPI.pm b/t/lib/FakeAPI.pm
index d51a469..0f53157 100644
--- a/t/lib/FakeAPI.pm
+++ b/t/lib/FakeAPI.pm
@@ -1,14 +1,31 @@
package FakeAPI;
use Moose;
use MooseX::Net::API;
+use LWP::UserAgent;
+use HTTP::Response;
+use JSON::XS;
net_api_declare demorest => (
- base_url => 'http://lumberjaph.net/demorest/rest',
+ base_url => "http://example.com/",
format => 'json',
format_mode => 'content-type',
authentication => 0,
username => 'foo',
password => 'bar',
+ useragent => sub {
+ my ($self) = @_;
+ my $ua = LWP::UserAgent->new();
+ $ua->add_handler(
+ request_send => sub {
+ my $request = shift;
+ my $res = HTTP::Response->new(200, 'OK');
+ $res->header('content-type' => 'application/json');
+ $res->content(encode_json {status => 1});
+ return $res;
+ }
+ );
+ return $ua;
+ },
);
net_api_method users => (
@@ -52,7 +69,8 @@ net_api_method delete_user => (
);
net_api_method auth_get_user => (
- description => 'fetch information about a specific user with authentication',
+ description =>
+ 'fetch information about a specific user with authentication',
method => 'GET',
path => '/auth_user/$id',
params => [qw/id/],