View | Details | Raw Unified | Return to bug 29772
Collapse All | Expand All

(-)a/t/db_dependent/api/v1/patrons.t (-7 / +26 lines)
Lines 662-670 subtest 'delete() tests' => sub { Link Here
662
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
662
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
663
663
664
        t::lib::Mocks::mock_preference('AnonymousPatron', $patron->borrowernumber);
664
        t::lib::Mocks::mock_preference('AnonymousPatron', $patron->borrowernumber);
665
        $t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber)
665
        $t->delete_ok( "//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber )
666
          ->status_is(403, 'Anonymous patron cannot be deleted')
666
          ->status_is( 409, 'Anonymous patron cannot be deleted' )
667
          ->json_is( { error => 'Anonymous patron cannot be deleted' } );
667
          ->json_is(
668
            {
669
                error      => 'Anonymous patron cannot be deleted',
670
                error_code => 'is_anonymous_patron'
671
            }
672
          );
668
        t::lib::Mocks::mock_preference('AnonymousPatron', 0); # back to default
673
        t::lib::Mocks::mock_preference('AnonymousPatron', 0); # back to default
669
674
670
        t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
675
        t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
Lines 682-702 subtest 'delete() tests' => sub { Link Here
682
687
683
        $t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber)
688
        $t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber)
684
          ->status_is(409, 'Patron with checkouts cannot be deleted')
689
          ->status_is(409, 'Patron with checkouts cannot be deleted')
685
          ->json_is( { error => 'Pending checkouts prevent deletion' } );
690
          ->json_is(
691
            {
692
                error      => 'Pending checkouts prevent deletion',
693
                error_code => 'has_checkouts'
694
            }
695
          );
686
696
687
        # Make sure it has no pending checkouts
697
        # Make sure it has no pending checkouts
688
        $checkout->delete;
698
        $checkout->delete;
689
699
690
        $t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber)
700
        $t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber)
691
          ->status_is(409, 'Patron with debt cannot be deleted')
701
          ->status_is(409, 'Patron with debt cannot be deleted')
692
          ->json_is( { error => 'Pending debts prevent deletion' } );
702
          ->json_is(
703
            {
704
                error      => 'Pending debts prevent deletion',
705
                error_code => 'has_debt'
706
            }
707
          );
693
708
694
        # Make sure it has no debt
709
        # Make sure it has no debt
695
        $patron->account->pay({ amount => 10, debits => [ $debit ] });
710
        $patron->account->pay({ amount => 10, debits => [ $debit ] });
696
711
697
        $t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber)
712
        $t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber)
698
          ->status_is(409, 'Patron with guarantees cannot be deleted')
713
          ->status_is(409, 'Patron with guarantees cannot be deleted')
699
          ->json_is( { error => 'Patron is a guarantor and it prevents deletion' } );
714
          ->json_is(
715
            {
716
                error      => 'Patron is a guarantor and it prevents deletion',
717
                error_code => 'has_guarantees'
718
            }
719
          );
700
720
701
        # Remove guarantee
721
        # Remove guarantee
702
        $patron->guarantee_relationships->delete;
722
        $patron->guarantee_relationships->delete;
703
- 

Return to bug 29772