From a775a33f33d6b441c7b5f9a8ab0638cb697fe432 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Tue, 14 Nov 2023 13:44:11 +0200 Subject: [PATCH] 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 --- t/db_dependent/Letters.t | 12 ++++++++++-- t/db_dependent/api/v1/erm_users.t | 7 ++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index 05a026a821..9f888030b2 100755 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -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' } ); diff --git a/t/db_dependent/api/v1/erm_users.t b/t/db_dependent/api/v1/erm_users.t index 379db6562f..f038105384 100755 --- a/t/db_dependent/api/v1/erm_users.t +++ b/t/db_dependent/api/v1/erm_users.t @@ -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( -- 2.34.1