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