From abcc81f7501ac86b528aa5cdabcea26a0049cc27 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Sun, 20 Dec 2009 15:52:22 +0100 Subject: remove and update some tests --- t/01_basic.t | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 't/01_basic.t') diff --git a/t/01_basic.t b/t/01_basic.t index 471f3dd..3154298 100644 --- a/t/01_basic.t +++ b/t/01_basic.t @@ -7,29 +7,36 @@ use FakeAPI; my $obj = FakeAPI->new; ok $obj, "... object created"; -ok $obj->meta->has_attribute('useragent'), +ok $obj->meta->has_attribute('api_useragent'), "... useragent attribute have been added"; -ok my $method = $obj->meta->find_method_by_name('bar'), - '... method bar have been created'; +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'; - -throws_ok { $obj->baz } qr/bla is declared as required, but is not present/, - "... check required params"; - -throws_ok { - $obj->bar( bar => 1, ); -} -qr/baz is declared as required, but is not present/, - "... check required params are present"; - -throws_ok { - $obj->bar( bar => 1, foo => 2, ); -} -qr/foo is not declared as a param/, "... check declared params"; +is $method->path, '/user/$id', '... get good path value'; ok my @methods = $obj->meta->local_api_methods(), '... get api methods'; -is scalar @methods, 3, '... got 3 methods in our API'; +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"; + +ok my $user = $obj->get_user( id => $users->[0]->{id} ), + "... fetch bruce wayne informations"; +is $user->{user}, "bruce wayne", "... get bruce wayne"; + +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(); +use Try::Tiny; +use YAML::Syck; +try { + my $res = $auth_obj->auth_get_user(id => 1); +}catch{ + warn Dump $_; +}; done_testing; -- cgit 1.4.1