8 my $base = 'http://localhost';
14 use Test::WWW::Mechanize::Catalyst 'RestTest';
15 use HTTP::Request::Common;
18 my $json = JSON->new->utf8;
20 my $mech = Test::WWW::Mechanize::Catalyst->new;
21 ok( my $schema = DBICTest->init_schema(), 'got schema' );
23 my $artist_view_url = "$base/api/rest/artist/";
28 GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' );
30 cmp_ok( $mech->status, '==', 200, 'open attempt okay' );
31 my %expected_response =
32 $schema->resultset('Artist')->find($id)->get_columns;
33 my $response = $json->decode( $mech->content );
36 { data => \%expected_response, success => 'true' },
37 'correct data returned'
44 GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' );
46 cmp_ok( $mech->status, '==', 400, 'open attempt not ok' );
47 my $response = $json->decode( $mech->content );
48 is( $response->{success}, 'false',
49 'not existing object fetch failed ok' );
51 $response->{messages}->[0],
52 qr/^No object found for id/,
53 'error message for not existing object fetch ok'
57 my $track_view_url = "$base/api/rest/track/";
62 GET( $track_view_url . $id, undef, 'Accept' => 'application/json' );
64 cmp_ok( $mech->status, '==', 200, 'got track with datetime object okay' );
65 my %expected_response =
66 $schema->resultset('Track')->find($id)->get_columns;
67 my $response = $json->decode( $mech->content );
70 { data => \%expected_response, success => 'true' },
71 'correct data returned for track with datetime'