X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=blobdiff_plain;f=t%2Frest%2Flist.t;h=ab2aa4ec47471064df7dea0daf3bd70f2e7e4a2b;hp=c7683f88577292c2d2bc53f761b6d0ec942b55e5;hb=11ba2ccc06f22b028f66fdfcad72ce3903345374;hpb=d273984026646e5b57c052deef3fcb9121122060 diff --git a/t/rest/list.t b/t/rest/list.t index c7683f8..ab2aa4e 100644 --- a/t/rest/list.t +++ b/t/rest/list.t @@ -21,6 +21,8 @@ ok(my $schema = DBICTest->init_schema(), 'got schema'); my $artist_list_url = "$base/api/rest/artist"; my $filtered_artist_list_url = "$base/api/rest/bound_artist"; my $producer_list_url = "$base/api/rest/producer"; +my $cd_list_url = "$base/api/rest/cd"; +my $track_list_url = "$base/api/rest/track"; # test open request { @@ -59,7 +61,6 @@ my $producer_list_url = "$base/api/rest/producer"; } { - $DB::single = 1; my $uri = URI->new( $producer_list_url ); my $req = GET( $uri, 'Accept' => 'text/x-json' ); $mech->request($req); @@ -72,7 +73,7 @@ my $producer_list_url = "$base/api/rest/producer"; { my $uri = URI->new( $artist_list_url ); - $uri->query_form({ 'search.cds.title' => 'Forkful of bees' }); + $uri->query_form({ 'search.cds.title' => 'Forkful of bees' }); my $req = GET( $uri, 'Accept' => 'text/x-json' ); $mech->request($req); cmp_ok( $mech->status, '==', 200, 'search related request okay' ); @@ -105,4 +106,54 @@ my $producer_list_url = "$base/api/rest/producer"; is_deeply( $response, { list => \@expected_response, success => 'true' }, 'correct data returned for class with setup_list_method specified' ); } +{ + my $uri = URI->new( $cd_list_url ); + $uri->query_form({ 'search.tracks.position' => '1', 'search.artist.name' => 'Caterwauler McCrae' }); + my $req = GET( $uri, 'Accept' => 'text/x-json' ); + $mech->request($req); + cmp_ok( $mech->status, '==', 200, 'search multiple params request okay' ); + my $response = JSON::Any->Load( $mech->content); + my @expected_response = map { { $_->get_columns } } $schema->resultset('CD')->search({ + 'artist.name' => 'Caterwauler McCrae', + 'tracks.position' => 1, + }, { + join => [qw/ artist tracks /], + })->all; + is_deeply( $response, { list => \@expected_response, success => 'true' }, 'correct data returned for multiple search params' ); +} + +# page specified in controller config (RT#56226) +{ + my $uri = URI->new( $track_list_url ); + $uri->query_form(); + my $req = GET( $uri, 'Accept' => 'text/x-json' ); + $mech->request($req); + cmp_ok( $mech->status, '==', 200, 'get first page ok' ); + my $response = JSON::Any->Load( $mech->content); + my @expected_response = map { { $_->get_columns } } $schema->resultset('Track')->search(undef, { + page => 1, + })->all; + is_deeply( $response, { list => \@expected_response, success => 'true', totalcount => 15 }, 'correct data returned for static configured paging' ); +} + +{ + my $uri = URI->new( $artist_list_url ); + $uri->query_form({ 'search.cds.track.title' => 'Suicidal' }); + my $req = GET( $uri, 'Accept' => 'text/x-json' ); + $mech->request($req); + cmp_ok( $mech->status, '==', 400, 'attempt with nonexisting relationship fails' ); + my $response = JSON::Any->Load( $mech->content); + is_deeply( $response->{messages}, ["track is neither a relationship nor a column\n"], 'correct error message returned' ); +} + +{ + my $uri = URI->new( $artist_list_url ); + $uri->query_form({ 'search.cds.tracks.foo' => 'Bar' }); + my $req = GET( $uri, 'Accept' => 'text/x-json' ); + $mech->request($req); + cmp_ok( $mech->status, '==', 400, 'attempt with nonexisting column fails' ); + my $response = JSON::Any->Load( $mech->content); + is_deeply( $response->{messages}, ['a database error has occured.'], 'correct error message returned' ); +} + done_testing();