removed debugging code in rest item test
[catagits/Catalyst-Controller-DBIC-API.git] / t / rest / 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;
16use JSON::Any;
17
18my $mech = Test::WWW::Mechanize::Catalyst->new;
19ok(my $schema = DBICTest->init_schema(), 'got schema');
20
21my $artist_view_url = "$base/api/rest/artist/";
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
15754afc 43my $track_view_url = "$base/api/rest/track/";
44
45{
46 my $id = 9;
47 my $req = GET( $track_view_url . $id, undef, 'Accept' => 'application/json' );
48 $mech->request($req);
49 cmp_ok( $mech->status, '==', 200, 'got track with datetime object okay' );
50 my %expected_response = $schema->resultset('Track')->find($id)->get_columns;
15754afc 51 my $response = JSON::Any->Load( $mech->content);
15754afc 52 is_deeply( $response, { data => \%expected_response, success => 'true' }, 'correct data returned for track with datetime' );
53}
54
609916e5 55done_testing();