8 my $base = 'http://localhost';
14 use Test::WWW::Mechanize::Catalyst 'RestTest';
15 use HTTP::Request::Common;
18 my $mech = Test::WWW::Mechanize::Catalyst->new;
19 ok(my $schema = DBICTest->init_schema(), 'got schema');
21 my $artist_view_url = "$base/api/rest/artist/";
25 my $req = GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' );
27 cmp_ok( $mech->status, '==', 200, 'open attempt okay' );
28 my %expected_response = $schema->resultset('Artist')->find($id)->get_columns;
29 my $response = JSON::Any->Load( $mech->content);
30 is_deeply( $response, { data => \%expected_response, success => 'true' }, 'correct data returned' );
35 my $req = GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' );
37 cmp_ok( $mech->status, '==', 400, 'open attempt not ok' );
38 my $response = JSON::Any->Load( $mech->content);
39 is($response->{success}, 'false', 'not existing object fetch failed ok');
40 like($response->{messages}->[0], qr/^No object found for id/, 'error message for not existing object fetch ok');
43 my $track_view_url = "$base/api/rest/track/";
47 my $req = GET( $track_view_url . $id, undef, 'Accept' => 'application/json' );
49 cmp_ok( $mech->status, '==', 200, 'got track with datetime object okay' );
50 my %expected_response = $schema->resultset('Track')->find($id)->get_columns;
51 my $response = JSON::Any->Load( $mech->content);
52 is_deeply( $response, { data => \%expected_response, success => 'true' }, 'correct data returned for track with datetime' );