Koha/t/db_dependent/api/v1/patrons_holds.t
Jonathan Druart afcf0c95b4
Bug 28670: Prevent api/v1/patrons_holds.t to fail randomly
12:01:12 koha_1       |     #   Failed test 'Holds retrieved'
12:01:12 koha_1       |     #   at t/db_dependent/api/v1/patrons_holds.t line 56.
12:01:12 koha_1       |     #     Structures begin differing at:
12:01:12 koha_1       |     #          $got->[0]{hold_id} = '256'
12:01:12 koha_1       |     #     $expected->[0]{hold_id} = '255'
12:01:12 koha_1       |     # Looks like you failed 1 test of 9.
12:01:12 koha_1       |
12:01:12 koha_1       | #   Failed test 'list() tests'
12:01:12 koha_1       | #   at t/db_dependent/api/v1/patrons_holds.t line 70.

This is a weird one, and the only solution I see it to force the order
we want to receive the holds.

I guess we should not rely on an order if no order by clause is passed

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2023-01-18 16:10:19 +00:00

70 lines
2.3 KiB
Perl
Executable file

#!/usr/bin/env perl
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 1;
use Test::Mojo;
use t::lib::TestBuilder;
use t::lib::Mocks;
use Koha::Database;
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new();
my $t = Test::Mojo->new('Koha::REST::V1');
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
subtest 'list() tests' => sub {
plan tests => 9;
$schema->storage->txn_begin;
my $patron = $builder->build_object({
class => 'Koha::Patrons',
value => { flags => 2 ** 4 } # 'borrowers' flag == 4
});
my $password = 'thePassword123';
$patron->set_password({ password => $password, skip_validation => 1 });
my $userid = $patron->userid;
$t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds')
->status_is( 200, 'SWAGGER3.2.2' )
->json_is( [] );
my $hold_1 = $builder->build_object({ class => 'Koha::Holds', value => { borrowernumber => $patron->id } });
my $hold_2 = $builder->build_object({ class => 'Koha::Holds', value => { borrowernumber => $patron->id } });
$t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron->id . '/holds?_order_by=+me.hold_id')
->status_is( 200, 'SWAGGER3.2.2' )
->json_is( '' => [ $hold_1->to_api, $hold_2->to_api ], 'Holds retrieved' );
my $non_existent_patron = $builder->build_object({ class => 'Koha::Patrons' });
my $non_existent_patron_id = $non_existent_patron->id;
# get rid of the patron
$non_existent_patron->delete;
$t->get_ok("//$userid:$password@/api/v1/patrons/" . $non_existent_patron_id . '/holds')
->status_is( 404 )
->json_is( '/error' => 'Patron not found' );
$schema->storage->txn_rollback;
};