From 45a2e630750f2382c04ae1ff74a1fa977aa71d19 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 18 Jul 2022 18:33:33 -0300 Subject: [PATCH] Bug 31183: Unit tests Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Item/Transfers.t | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Item/Transfers.t b/t/db_dependent/Koha/Item/Transfers.t index 324842b637..35cce33bcb 100755 --- a/t/db_dependent/Koha/Item/Transfers.t +++ b/t/db_dependent/Koha/Item/Transfers.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use Koha::Item::Transfer; use Koha::Item::Transfers; @@ -109,3 +109,25 @@ subtest 'daterequested tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'filter_by_current() tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $transfer_1 = $builder->build_object({ class => 'Koha::Item::Transfers', value => { datearrived => \'NOW()', datecancelled => undef } }); + my $transfer_2 = $builder->build_object({ class => 'Koha::Item::Transfers', value => { datearrived => undef, datecancelled => \'NOW()' } }); + my $transfer_3 = $builder->build_object({ class => 'Koha::Item::Transfers', value => { datearrived => undef, datecancelled => undef } }); + + my $rs = Koha::Item::Transfers->search({ branchtransfer_id => [ $transfer_1->id, $transfer_2->id, $transfer_3->id ] }); + + is( $rs->count, 3, 'Resultset has 3 transfers' ); + + $rs = $rs->filter_by_current; + + is( $rs->count, 1, 'Filtered resultset has 1 transfer' ); + is( $rs->next->id, $transfer_3->id, 'Only current transfer left on the resultset' ); + + $schema->storage->txn_rollback; +}; -- 2.25.1