From 429d56d3894cffb4febe45616a3073e95191af67 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 21 May 2020 17:48:21 -0300 Subject: [PATCH] Bug 25570: Regression tests 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 Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit 2220ce4d50998bef1dcea787d212a287a802b0aa) Signed-off-by: Lucas Gass (cherry picked from commit fc8bde417820d2f287df997a44136ea0b504b0f7) Signed-off-by: Aleisha Amohia --- t/db_dependent/Koha/REST/Plugin/Objects.t | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t index 9551fff64f..e4e66c47b0 100644 --- a/t/db_dependent/Koha/REST/Plugin/Objects.t +++ b/t/db_dependent/Koha/REST/Plugin/Objects.t @@ -99,6 +99,7 @@ sub to_api { use Test::More tests => 3; use Test::Mojo; +use t::lib::Mocks; use t::lib::TestBuilder; use Koha::Database; @@ -109,7 +110,7 @@ my $t = Test::Mojo->new; subtest 'objects.search helper' => sub { - plan tests => 38; + plan tests => 44; $schema->storage->txn_begin; @@ -191,6 +192,25 @@ subtest 'objects.search helper' => sub { ->json_is('/2/city_name' => 'Manuelab') ->json_is('/3/city_name' => '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; }; -- 2.39.5