From ebf11669c1b2ac3af22805a9a620e961b5d9983b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 22 Oct 2024 17:15:01 +0100 Subject: [PATCH] Bug 38175: (QA follow-up) Unit test for filter_by_active change We now filter out 'cancelled' and 'completed' bookings in the filter_by_active method. We need tests for that. Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Bookings.t | 46 +++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/t/db_dependent/Koha/Bookings.t b/t/db_dependent/Koha/Bookings.t index 699daaebab5..40b3ce1bcbd 100755 --- a/t/db_dependent/Koha/Bookings.t +++ b/t/db_dependent/Koha/Bookings.t @@ -33,7 +33,7 @@ my $builder = t::lib::TestBuilder->new; subtest 'filter_by_active' => sub { - plan tests => 5; + plan tests => 7; $schema->storage->txn_begin; @@ -50,7 +50,9 @@ subtest 'filter_by_active' => sub { value => { biblio_id => $biblio->biblionumber, start_date => $start_ago, - end_date => $end_hour + end_date => $end_hour, + status => 'new' + } } ); @@ -62,7 +64,9 @@ subtest 'filter_by_active' => sub { value => { biblio_id => $biblio->biblionumber, start_date => $start_ago, - end_date => $end_ago + end_date => $end_ago, + status => 'new' + } } ); @@ -74,7 +78,9 @@ subtest 'filter_by_active' => sub { value => { biblio_id => $biblio->biblionumber, start_date => $start_hour, - end_date => $end_hour + end_date => $end_hour, + status => 'new' + } } ); @@ -86,7 +92,8 @@ subtest 'filter_by_active' => sub { value => { biblio_id => $biblio->biblionumber, start_date => $start_day, - end_date => $end_day + end_date => $end_day, + status => 'new' } } ); @@ -98,7 +105,8 @@ subtest 'filter_by_active' => sub { value => { biblio_id => $biblio->biblionumber, start_date => $start_day, - end_date => $end_ago + end_date => $end_ago, + status => 'new' } } ); @@ -107,5 +115,31 @@ subtest 'filter_by_active' => sub { 'EDGE CASE: Booking starting in future, already ended is not counted - should be impossible, but good check' ); + $builder->build_object( + { + class => 'Koha::Bookings', + value => { + biblio_id => $biblio->biblionumber, + start_date => $start_day, + end_date => $end_day, + status => 'cancelled' + } + } + ); + is( $biblio->bookings->filter_by_active->count, 3, 'Cancelled bookings are not counted' ); + + $builder->build_object( + { + class => 'Koha::Bookings', + value => { + biblio_id => $biblio->biblionumber, + start_date => $start_day, + end_date => $end_day, + status => 'completed' + } + } + ); + is( $biblio->bookings->filter_by_active->count, 3, 'Completed bookings are not counted' ); + $schema->storage->txn_rollback; }; -- 2.47.0