Bug 31183: Unit tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomás Cohen Arazi 2022-07-18 18:33:33 -03:00
parent a5dfa2d490
commit 3ab8807d7e
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -19,7 +19,7 @@
use Modern::Perl; use Modern::Perl;
use Test::More tests => 3; use Test::More tests => 4;
use Koha::Item::Transfer; use Koha::Item::Transfer;
use Koha::Item::Transfers; use Koha::Item::Transfers;
@ -109,3 +109,25 @@ subtest 'daterequested tests' => sub {
$schema->storage->txn_rollback; $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;
};