From cf553d559f4cb66f3d568993292f4547127d8b61 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 6 May 2025 15:46:36 -0300 Subject: [PATCH] Bug 39845: Unit tests --- t/db_dependent/Koha/Acquisition/Orders.t | 52 +++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Acquisition/Orders.t b/t/db_dependent/Koha/Acquisition/Orders.t index 288e9ee6463..b05d9954823 100755 --- a/t/db_dependent/Koha/Acquisition/Orders.t +++ b/t/db_dependent/Koha/Acquisition/Orders.t @@ -20,7 +20,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Exception; use t::lib::TestBuilder; @@ -213,3 +213,53 @@ subtest 'filter_by_obsolete and cancel' => sub { $schema->storage->txn_rollback; }; + +subtest 'unreceived_totals() tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $empty_resultset = Koha::Acquisition::Orders->search->empty(); + + my $result = $empty_resultset->unreceived_totals(); + is( $result->{items_count}, 0, 'Zero unreceived items' ); + is( $result->{total_replacement_price}, 0, 'Zero cost for 0 items' ); + + my $rrp = 2.31; + + my $order_1 = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { quantity => 10, quantityreceived => 5, rrp => $rrp } + } + ); + my $order_2 = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { quantity => 10, quantityreceived => 4, rrp => $rrp } + } + ); + my $order_3 = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { quantity => 10, quantityreceived => 3, rrp => $rrp } + } + ); + + my $rs = Koha::Acquisition::Orders->search( + { + ordernumber => [ + $order_1->id, + $order_2->id, + $order_3->id, + ] + } + ); + + $result = $rs->unreceived_totals(); + is( $result->{items_count}, 18, '18 unreceived items' ); + is( $result->{total_replacement_price}, 18 * $rrp, 'rrp * 18' ); + + $schema->storage->txn_rollback; +}; -- 2.49.0