Bug 12133: Fix failing tests

Tests in erm_users.t and Letters.t failed because when
we mock patrons they receive category where setting
can_be_guarantee is not 0. This triggers error "Child
patron cannot be a guarantor". We also need to mock
syspref "ChildNeedsGuarantor" accordingly.

To test prove t/db_dependent/api/v1/erm_users.t and
t/db_dependent/Letters.t.

Sponsored-by: Koha-Suomi Oy
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Emmi Takkinen 2023-11-14 13:44:11 +02:00 committed by Tomas Cohen Arazi
parent 6be4e96a3a
commit f7d47ffc81
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 16 additions and 3 deletions

View File

@ -1032,10 +1032,18 @@ subtest 'Test guarantor handling in SendQueuedMessages' => sub {
plan tests => 19;
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'test' );
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 1 );
my $patron = Koha::Patrons->find($borrowernumber);
my $guarantor1 = $builder->build_object( { class => 'Koha::Patrons', value => { email => 'g1@email.com' } } );
my $guarantor2 = $builder->build_object( { class => 'Koha::Patrons', value => { email => 'g2@email.com' } } );
my $patron_category =
$builder->build( { source => 'Category', value => { category_type => 'A', can_be_guarantee => 0 } } )
->{categorycode};
my $guarantor1 = $builder->build_object(
{ class => 'Koha::Patrons', value => { email => 'g1@email.com', categorycode => $patron_category } } );
my $guarantor2 = $builder->build_object(
{ class => 'Koha::Patrons', value => { email => 'g2@email.com', categorycode => $patron_category } } );
$patron->add_guarantor( { guarantor_id => $guarantor1->borrowernumber, relationship => 'test' } );
$patron->add_guarantor( { guarantor_id => $guarantor2->borrowernumber, relationship => 'test' } );

View File

@ -31,6 +31,7 @@ my $builder = t::lib::TestBuilder->new;
my $t = Test::Mojo->new('Koha::REST::V1');
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 );
subtest 'list() tests' => sub {
@ -38,7 +39,11 @@ subtest 'list() tests' => sub {
$schema->storage->txn_begin;
Koha::Patrons->search->update( { flags => 0 } );
my $patron_category =
$builder->build( { source => 'Category', value => { category_type => 'A', can_be_guarantee => 0 } } )
->{categorycode};
Koha::Patrons->search->update( { flags => 0, categorycode => $patron_category } );
$schema->resultset('UserPermission')->delete;
my $librarian = $builder->build_object(