6 my $base = 'http://localhost';
12 use Test::WWW::Mechanize::Catalyst 'RestTest';
13 use HTTP::Request::Common;
16 my $json = JSON->new->utf8;
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/";
26 GET( $artist_view_url . $id, 'Accept' => 'application/json' );
28 cmp_ok( $mech->status, '==', 200, 'open attempt okay' );
29 my %expected_response =
30 $schema->resultset('Artist')->find($id)->get_columns;
31 my $response = $json->decode( $mech->content );
32 #artist does not have use_json_boolean => 1, so true values are stringified to 'true'
35 { data => \%expected_response, success => 'true' },
36 'correct data returned'
43 GET( $artist_view_url . $id, 'Accept' => 'application/json' );
45 cmp_ok( $mech->status, '==', 400, 'open attempt not ok' );
46 my $response = $json->decode( $mech->content );
47 is( $response->{success}, 'false',
48 'not existing object fetch failed ok' );
50 $response->{messages}->[0],
51 qr/^No object found for id/,
52 'error message for not existing object fetch ok'
56 my $track_view_url = "$base/api/rest/track/";
61 GET( $track_view_url . $id, 'Accept' => 'application/json' );
63 cmp_ok( $mech->status, '==', 200, 'got track with datetime object okay' );
64 my %expected_response =
65 $schema->resultset('Track')->find($id)->get_columns;
66 my $response = $json->decode( $mech->content );
69 { data => \%expected_response, success => JSON::true },
70 'correct data returned for track with datetime'
76 GET( $artist_view_url . 'action_with_error', 'Accept' => 'application/json' );
78 cmp_ok( $mech->status, '==', 404, 'action returned error 404' );
79 my $response = $json->decode( $mech->content );
82 { success => 'false' },
83 'correct data returned'