use JSON instead of JSON::Any to get rid of the CPAN Testers failures when only JSON...
[catagits/Catalyst-Controller-DBIC-API.git] / t / rpc / item.t
CommitLineData
609916e5 1use 5.6.0;
2
3use strict;
4use warnings;
5
6use lib 't/lib';
7
8my $base = 'http://localhost';
9
10use RestTest;
11use DBICTest;
12use URI;
13use Test::More;
14use Test::WWW::Mechanize::Catalyst 'RestTest';
15use HTTP::Request::Common;
0b0bf911 16use JSON;
17
18my $json = JSON->new->utf8;
609916e5 19
20my $mech = Test::WWW::Mechanize::Catalyst->new;
0b0bf911 21ok( my $schema = DBICTest->init_schema(), 'got schema' );
609916e5 22
23my $artist_view_url = "$base/api/rpc/artist/id/";
24
25{
26 my $id = 1;
0b0bf911 27 my $req =
28 GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' );
609916e5 29 $mech->request($req);
30 cmp_ok( $mech->status, '==', 200, 'open attempt okay' );
0b0bf911 31 my %expected_response =
32 $schema->resultset('Artist')->find($id)->get_columns;
33 my $response = $json->decode( $mech->content );
34 is_deeply(
35 $response,
36 { data => \%expected_response, success => 'true' },
37 'correct data returned'
38 );
609916e5 39}
40
41{
42 my $id = 5;
0b0bf911 43 my $req =
44 GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' );
609916e5 45 $mech->request($req);
46 cmp_ok( $mech->status, '==', 400, 'open attempt not ok' );
0b0bf911 47 my $response = $json->decode( $mech->content );
48 is( $response->{success}, 'false',
49 'not existing object fetch failed ok' );
50 like(
51 $response->{messages}->[0],
52 qr/^No object found for id/,
53 'error message for not existing object fetch ok'
54 );
609916e5 55}
56
57done_testing();