Bug 25570: (follow-up) Fix tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 21 May 2020 21:25:46 +0000 (18:25 -0300)
committerVictor Grousset/tuxayo <victor@tuxayo.net>
Thu, 23 Jul 2020 22:12:37 +0000 (00:12 +0200)
This patch fixes the libraries tests, that expected the old behaviour

To test:
1. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/libraries.t
=> FAIL: Tests fail
2. Apply this patch
3. Repeat 1
=> SUCCESS: Tests pass!
4. Sign off :-D

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 b115dfeca649f2f35e0290ead85f2626eabd0829)

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

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

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

t/db_dependent/api/v1/libraries.t

index 5ac8ecc..6bc94ac 100644 (file)
@@ -24,6 +24,8 @@ use Test::Warn;
 use t::lib::TestBuilder;
 use t::lib::Mocks;
 
+use List::Util qw(min);
+
 use Koha::Libraries;
 use Koha::Database;
 
@@ -35,7 +37,7 @@ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
 my $t = Test::Mojo->new('Koha::REST::V1');
 
 subtest 'list() tests' => sub {
-    plan tests => 8;
+    plan tests => 7;
 
     $schema->storage->txn_begin;
 
@@ -54,12 +56,13 @@ subtest 'list() tests' => sub {
     $another_library = $builder->build_object({ class => 'Koha::Libraries', value => $another_library });
 
     ## Authorized user tests
-    my $count_of_libraries = Koha::Libraries->search->count;
     # Make sure we are returned with the correct amount of libraries
     $t->get_ok( "//$userid:$password@/api/v1/libraries" )
-      ->status_is( 200, 'SWAGGER3.2.2' )
-      ->json_has('/'.($count_of_libraries-1).'/library_id')
-      ->json_hasnt('/'.($count_of_libraries).'/library_id');
+      ->status_is( 200, 'SWAGGER3.2.2' );
+
+    my $response_count = scalar @{ $t->tx->res->json };
+    my $expected_count = min( Koha::Libraries->count, C4::Context->preference('RESTdefaultPageSize') );
+    is( $response_count, $expected_count, 'Results count is paginated');
 
     subtest 'query parameters' => sub {