remove trailing newlines from error messages
[catagits/Catalyst-Controller-DBIC-API.git] / t / rest / list.t
index 6d73b59..783aa4c 100644 (file)
@@ -22,6 +22,7 @@ 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
 {
@@ -72,7 +73,7 @@ my $cd_list_url = "$base/api/rest/cd";
 
 {
   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' );
@@ -121,4 +122,38 @@ my $cd_list_url = "$base/api/rest/cd";
   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'], '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();