added REST and RPC bulk_update tests for nonexisting objects
[catagits/Catalyst-Controller-DBIC-API.git] / t / rpc / item.t
1 use 5.6.0;
2
3 use strict;
4 use warnings;
5
6 use lib 't/lib';
7
8 my $base = 'http://localhost';
9
10 use RestTest;
11 use DBICTest;
12 use URI;
13 use Test::More;
14 use Test::WWW::Mechanize::Catalyst 'RestTest';
15 use HTTP::Request::Common;
16 use JSON::Any;
17
18 my $mech = Test::WWW::Mechanize::Catalyst->new;
19 ok(my $schema = DBICTest->init_schema(), 'got schema');
20
21 my $artist_view_url = "$base/api/rpc/artist/id/";
22
23 {
24     my $id = 1;
25     my $req = GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' );
26     $mech->request($req);
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' );
31 }
32
33 {
34     my $id = 5;
35     my $req = GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' );
36     $mech->request($req);
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');
41 }
42
43 done_testing();