X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=blobdiff_plain;f=t%2Frest%2Fitem.t;fp=t%2Frest%2Fitem.t;h=ff9a51b11b571278c1f79993afb94ca186adc2b3;hp=29d2f1e066579ea989890676650c916086277406;hb=0b0bf9111127c9fdad1e456169ec4cdd15b160f9;hpb=e17f1f8e991b57bf9f7f23547c0c9af8b3012569 diff --git a/t/rest/item.t b/t/rest/item.t index 29d2f1e..ff9a51b 100644 --- a/t/rest/item.t +++ b/t/rest/item.t @@ -13,43 +13,63 @@ use URI; use Test::More; use Test::WWW::Mechanize::Catalyst 'RestTest'; use HTTP::Request::Common; -use JSON::Any; +use JSON; + +my $json = JSON->new->utf8; my $mech = Test::WWW::Mechanize::Catalyst->new; -ok(my $schema = DBICTest->init_schema(), 'got schema'); +ok( my $schema = DBICTest->init_schema(), 'got schema' ); my $artist_view_url = "$base/api/rest/artist/"; { my $id = 1; - my $req = GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' ); + my $req = + GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' ); $mech->request($req); cmp_ok( $mech->status, '==', 200, 'open attempt okay' ); - my %expected_response = $schema->resultset('Artist')->find($id)->get_columns; - my $response = JSON::Any->Load( $mech->content); - is_deeply( $response, { data => \%expected_response, success => 'true' }, 'correct data returned' ); + my %expected_response = + $schema->resultset('Artist')->find($id)->get_columns; + my $response = $json->decode( $mech->content ); + is_deeply( + $response, + { data => \%expected_response, success => 'true' }, + 'correct data returned' + ); } { my $id = 5; - my $req = GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' ); + my $req = + GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' ); $mech->request($req); cmp_ok( $mech->status, '==', 400, 'open attempt not ok' ); - my $response = JSON::Any->Load( $mech->content); - is($response->{success}, 'false', 'not existing object fetch failed ok'); - like($response->{messages}->[0], qr/^No object found for id/, 'error message for not existing object fetch ok'); + my $response = $json->decode( $mech->content ); + is( $response->{success}, 'false', + 'not existing object fetch failed ok' ); + like( + $response->{messages}->[0], + qr/^No object found for id/, + 'error message for not existing object fetch ok' + ); } my $track_view_url = "$base/api/rest/track/"; { my $id = 9; - my $req = GET( $track_view_url . $id, undef, 'Accept' => 'application/json' ); + my $req = + GET( $track_view_url . $id, undef, 'Accept' => 'application/json' ); $mech->request($req); cmp_ok( $mech->status, '==', 200, 'got track with datetime object okay' ); - my %expected_response = $schema->resultset('Track')->find($id)->get_columns; - my $response = JSON::Any->Load( $mech->content); - is_deeply( $response, { data => \%expected_response, success => 'true' }, 'correct data returned for track with datetime' ); + my %expected_response = + $schema->resultset('Track')->find($id)->get_columns; + my $response = $json->decode( $mech->content ); + is_deeply( + $response, + { data => \%expected_response, success => 'true' }, + 'correct data returned for track with datetime' + ); } done_testing();