Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 8; |
23 |
|
23 |
|
24 |
use Test::Exception; |
24 |
use Test::Exception; |
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
Lines 495-501
subtest 'is_pickup_location_valid() tests' => sub {
Link Here
|
495 |
|
495 |
|
496 |
subtest 'cancel() tests' => sub { |
496 |
subtest 'cancel() tests' => sub { |
497 |
|
497 |
|
498 |
plan tests => 6; |
498 |
plan tests => 7; |
499 |
|
499 |
|
500 |
$schema->storage->txn_begin; |
500 |
$schema->storage->txn_begin; |
501 |
|
501 |
|
Lines 614-619
subtest 'cancel() tests' => sub {
Link Here
|
614 |
)->cancel({ skip_holds_queue => 0 }); |
614 |
)->cancel({ skip_holds_queue => 0 }); |
615 |
}; |
615 |
}; |
616 |
|
616 |
|
|
|
617 |
subtest 'cancellation_requests handling' => sub { |
618 |
|
619 |
plan tests => 2; |
620 |
|
621 |
my $item = $builder->build_sample_item; |
622 |
my $hold = $builder->build_object( |
623 |
{ |
624 |
class => 'Koha::Holds', |
625 |
value => { |
626 |
biblionumber => $item->biblionumber, |
627 |
itemnumber => $item->itemnumber, |
628 |
found => 'W', |
629 |
} |
630 |
} |
631 |
); |
632 |
|
633 |
my $request = $hold->add_cancellation_request( |
634 |
{ |
635 |
requester_id => $hold->borrowernumber, |
636 |
} |
637 |
); |
638 |
|
639 |
# limit noise |
640 |
t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', undef ); |
641 |
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); |
642 |
|
643 |
is( $request->status, 'requested' ); |
644 |
|
645 |
$hold->cancel; |
646 |
|
647 |
$request->discard_changes; |
648 |
|
649 |
is( $request->status, 'accepted', 'When holds are cancellaed, cancellation requests are implicitly accepted' ); |
650 |
}; |
651 |
|
617 |
$schema->storage->txn_rollback; |
652 |
$schema->storage->txn_rollback; |
618 |
}; |
653 |
}; |
619 |
|
654 |
|
Lines 656-658
subtest 'suspend_hold() and resume() tests' => sub {
Link Here
|
656 |
|
691 |
|
657 |
$schema->storage->txn_rollback; |
692 |
$schema->storage->txn_rollback; |
658 |
}; |
693 |
}; |
659 |
- |
694 |
|
|
|
695 |
subtest 'cancellation_requests() and add_cancellation_request() tests' => sub { |
696 |
|
697 |
plan tests => 8; |
698 |
|
699 |
$schema->storage->txn_begin; |
700 |
|
701 |
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); |
702 |
|
703 |
my $hold = $builder->build_object( { class => 'Koha::Holds', } ); |
704 |
|
705 |
is( $hold->cancellation_requests->count, 0 ); |
706 |
|
707 |
# Add two cancellation requests |
708 |
my $request_1 = $hold->add_cancellation_request; |
709 |
|
710 |
is( $request_1->requester_id, undef ); |
711 |
is( $request_1->status, 'requested', 'Default value set' ); |
712 |
isnt( $request_1->creation_date, undef ); |
713 |
|
714 |
my $requester = $builder->build_object( { class => 'Koha::Patrons' } ); |
715 |
my $creation_date = '2021-06-25 14:05:35'; |
716 |
|
717 |
my $request_2 = $hold->add_cancellation_request( |
718 |
{ |
719 |
requester_id => $requester->id, |
720 |
creation_date => $creation_date, |
721 |
} |
722 |
); |
723 |
|
724 |
is( $request_2->requester_id, $requester->id, 'Passed requester_id set' ); |
725 |
is( $request_2->creation_date, $creation_date, 'Passed creation_date set' ); |
726 |
|
727 |
is( $hold->cancellation_requests->count, 2 ); |
728 |
|
729 |
subtest 'owner_cancellation_request() tests' => sub { |
730 |
|
731 |
plan tests => 3; |
732 |
|
733 |
my $owner_request = $hold->owner_cancellation_request; |
734 |
|
735 |
ok( !$owner_request ); |
736 |
|
737 |
$hold->add_cancellation_request({ requester_id => $hold->borrowernumber }); |
738 |
|
739 |
$owner_request = $hold->owner_cancellation_request; |
740 |
|
741 |
is( ref($owner_request), 'Koha::Hold::CancellationRequest' ); |
742 |
is( $owner_request->requester_id, $hold->borrowernumber ); |
743 |
}; |
744 |
|
745 |
$schema->storage->txn_rollback; |
746 |
}; |
747 |
|
748 |
subtest 'cancellation_requestable_from_opac() tests' => sub { |
749 |
|
750 |
plan tests => 5; |
751 |
|
752 |
$schema->storage->txn_begin; |
753 |
|
754 |
my $category = |
755 |
$builder->build_object( { class => 'Koha::Patron::Categories' } ); |
756 |
my $item_home_library = |
757 |
$builder->build_object( { class => 'Koha::Libraries' } ); |
758 |
my $patron_home_library = |
759 |
$builder->build_object( { class => 'Koha::Libraries' } ); |
760 |
|
761 |
my $item = |
762 |
$builder->build_sample_item( { library => $item_home_library->id } ); |
763 |
my $patron = $builder->build_object( |
764 |
{ |
765 |
class => 'Koha::Patrons', |
766 |
value => { branchcode => $patron_home_library->id } |
767 |
} |
768 |
); |
769 |
|
770 |
subtest 'Exception cases' => sub { |
771 |
|
772 |
plan tests => 4; |
773 |
|
774 |
my $hold = $builder->build_object( |
775 |
{ |
776 |
class => 'Koha::Holds', |
777 |
value => { |
778 |
itemnumber => undef, |
779 |
found => undef, |
780 |
borrowernumber => $patron->id |
781 |
} |
782 |
} |
783 |
); |
784 |
|
785 |
throws_ok { $hold->cancellation_requestable_from_opac; } |
786 |
'Koha::Exceptions::InvalidStatus', |
787 |
'Exception thrown because hold is not waiting'; |
788 |
|
789 |
is( $@->invalid_status, 'hold_not_waiting' ); |
790 |
|
791 |
$hold = $builder->build_object( |
792 |
{ |
793 |
class => 'Koha::Holds', |
794 |
value => { |
795 |
itemnumber => undef, |
796 |
found => 'W', |
797 |
borrowernumber => $patron->id |
798 |
} |
799 |
} |
800 |
); |
801 |
|
802 |
throws_ok { $hold->cancellation_requestable_from_opac; } |
803 |
'Koha::Exceptions::InvalidStatus', |
804 |
'Exception thrown because waiting hold has no item linked'; |
805 |
|
806 |
is( $@->invalid_status, 'no_item_linked' ); |
807 |
}; |
808 |
|
809 |
# set default rule to enabled |
810 |
Koha::CirculationRules->set_rule( |
811 |
{ |
812 |
categorycode => '*', |
813 |
itemtype => '*', |
814 |
branchcode => '*', |
815 |
rule_name => 'waiting_hold_cancellation', |
816 |
rule_value => 1, |
817 |
} |
818 |
); |
819 |
|
820 |
my $hold = $builder->build_object( |
821 |
{ |
822 |
class => 'Koha::Holds', |
823 |
value => { |
824 |
itemnumber => $item->id, |
825 |
found => 'W', |
826 |
borrowernumber => $patron->id |
827 |
} |
828 |
} |
829 |
); |
830 |
|
831 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', |
832 |
'ItemHomeLibrary' ); |
833 |
|
834 |
Koha::CirculationRules->set_rule( |
835 |
{ |
836 |
categorycode => $patron->categorycode, |
837 |
itemtype => $item->itype, |
838 |
branchcode => $item->homebranch, |
839 |
rule_name => 'waiting_hold_cancellation', |
840 |
rule_value => 0, |
841 |
} |
842 |
); |
843 |
|
844 |
ok( !$hold->cancellation_requestable_from_opac ); |
845 |
|
846 |
Koha::CirculationRules->set_rule( |
847 |
{ |
848 |
categorycode => $patron->categorycode, |
849 |
itemtype => $item->itype, |
850 |
branchcode => $item->homebranch, |
851 |
rule_name => 'waiting_hold_cancellation', |
852 |
rule_value => 1, |
853 |
} |
854 |
); |
855 |
|
856 |
ok( |
857 |
$hold->cancellation_requestable_from_opac, |
858 |
'Make sure it is picking the right circulation rule' |
859 |
); |
860 |
|
861 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); |
862 |
|
863 |
Koha::CirculationRules->set_rule( |
864 |
{ |
865 |
categorycode => $patron->categorycode, |
866 |
itemtype => $item->itype, |
867 |
branchcode => $patron->branchcode, |
868 |
rule_name => 'waiting_hold_cancellation', |
869 |
rule_value => 0, |
870 |
} |
871 |
); |
872 |
|
873 |
ok( !$hold->cancellation_requestable_from_opac ); |
874 |
|
875 |
Koha::CirculationRules->set_rule( |
876 |
{ |
877 |
categorycode => $patron->categorycode, |
878 |
itemtype => $item->itype, |
879 |
branchcode => $patron->branchcode, |
880 |
rule_name => 'waiting_hold_cancellation', |
881 |
rule_value => 1, |
882 |
} |
883 |
); |
884 |
|
885 |
ok( |
886 |
$hold->cancellation_requestable_from_opac, |
887 |
'Make sure it is picking the right circulation rule' |
888 |
); |
889 |
|
890 |
$schema->storage->txn_rollback; |
891 |
}; |