Bug 25570: Regression tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 21 May 2020 20:48:21 +0000 (17:48 -0300)
committerVictor Grousset/tuxayo <victor@tuxayo.net>
Thu, 23 Jul 2020 22:12:28 +0000 (00:12 +0200)
This tests verify that the default behaviour is to paginate the results.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> FAIL: $c->objects->search doesn't paginate results by default

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 2220ce4d50998bef1dcea787d212a287a802b0aa)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit fc8bde417820d2f287df997a44136ea0b504b0f7)

Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>

(cherry picked from commit 429d56d3894cffb4febe45616a3073e95191af67)
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>

t/db_dependent/Koha/REST/Plugin/Objects.t

index a65d949..6502d5d 100644 (file)
@@ -82,6 +82,7 @@ sub to_api {
 use Test::More tests => 2;
 use Test::Mojo;
 
+use t::lib::Mocks;
 use t::lib::TestBuilder;
 use Koha::Database;
 
@@ -92,7 +93,7 @@ my $builder = t::lib::TestBuilder->new;
 
 subtest 'objects.search helper' => sub {
 
-    plan tests => 90;
+    plan tests => 96;
 
     my $t = Test::Mojo->new;
 
@@ -239,6 +240,25 @@ subtest 'objects.search helper' => sub {
         ->json_is('/1/nombre' => 'Manuela')
         ->json_is('/2/nombre' => 'Emanuel');
 
+    # Add 20 more cities
+    for ( 1..20 ) {
+        $builder->build_object({ class => 'Koha::Cities' });
+    }
+
+    t::lib::Mocks::mock_preference('RESTdefaultPageSize', 20 );
+    $t->get_ok('/cities')
+      ->status_is(200);
+
+    my $response_count = scalar @{ $t->tx->res->json };
+    is( $response_count, 20, 'RESTdefaultPageSize is honoured by default (20)' );
+
+    t::lib::Mocks::mock_preference('RESTdefaultPageSize', 5 );
+    $t->get_ok('/cities')
+      ->status_is(200);
+
+    $response_count = scalar @{ $t->tx->res->json };
+    is( $response_count, 5, 'RESTdefaultPageSize is honoured by default (5)' );
+
     $schema->storage->txn_rollback;
 };