|
Lines 31-36
use Koha::Database;
Link Here
|
| 31 |
use Koha::DateUtils qw(dt_from_string output_pref); |
31 |
use Koha::DateUtils qw(dt_from_string output_pref); |
| 32 |
use Koha::Exceptions::Patron; |
32 |
use Koha::Exceptions::Patron; |
| 33 |
use Koha::Exceptions::Patron::Attribute; |
33 |
use Koha::Exceptions::Patron::Attribute; |
|
|
34 |
use Koha::Old::Patrons; |
| 34 |
use Koha::Patron::Attributes; |
35 |
use Koha::Patron::Attributes; |
| 35 |
use Koha::Patron::Debarments qw( AddDebarment ); |
36 |
use Koha::Patron::Debarments qw( AddDebarment ); |
| 36 |
|
37 |
|
|
Lines 640-646
subtest 'delete() tests' => sub {
Link Here
|
| 640 |
$schema->storage->txn_rollback; |
641 |
$schema->storage->txn_rollback; |
| 641 |
|
642 |
|
| 642 |
subtest 'librarian access test' => sub { |
643 |
subtest 'librarian access test' => sub { |
| 643 |
plan tests => 8; |
644 |
plan tests => 18; |
| 644 |
|
645 |
|
| 645 |
$schema->storage->txn_begin; |
646 |
$schema->storage->txn_begin; |
| 646 |
|
647 |
|
|
Lines 665-675
subtest 'delete() tests' => sub {
Link Here
|
| 665 |
->status_is(403, 'Anonymous patron cannot be deleted') |
666 |
->status_is(403, 'Anonymous patron cannot be deleted') |
| 666 |
->json_is( { error => 'Anonymous patron cannot be deleted' } ); |
667 |
->json_is( { error => 'Anonymous patron cannot be deleted' } ); |
| 667 |
|
668 |
|
|
|
669 |
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' ); |
| 670 |
|
| 671 |
my $checkout = $builder->build_object( |
| 672 |
{ |
| 673 |
class => 'Koha::Checkouts', |
| 674 |
value => { borrowernumber => $patron->borrowernumber } |
| 675 |
} |
| 676 |
); |
| 677 |
my $debit = $patron->account->add_debit({ amount => 10, interface => 'intranet', type => 'MANUAL' }); |
| 678 |
my $guarantee = $builder->build_object({ class => 'Koha::Patrons' }); |
| 679 |
|
| 680 |
$guarantee->add_guarantor({ guarantor_id => $patron->id, relationship => 'parent' }); |
| 681 |
|
| 682 |
$t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber) |
| 683 |
->status_is(409, 'Patron with checkouts cannot be deleted') |
| 684 |
->json_is( { error => 'Pending checkouts prevent deletion' } ); |
| 685 |
|
| 686 |
# Make sure it has no pending checkouts |
| 687 |
$checkout->delete; |
| 688 |
|
| 689 |
$t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber) |
| 690 |
->status_is(409, 'Patron with debt cannot be deleted') |
| 691 |
->json_is( { error => 'Pending debts prevent deletion' } ); |
| 692 |
|
| 693 |
# Make sure it has no debt |
| 694 |
$patron->account->pay({ amount => 10, debits => [ $debit ] }); |
| 695 |
|
| 696 |
$t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber) |
| 697 |
->status_is(409, 'Patron with guarantees cannot be deleted') |
| 698 |
->json_is( { error => 'Patron is a guarantor and it prevents deletion' } ); |
| 699 |
|
| 700 |
# Remove guarantee |
| 701 |
$patron->guarantee_relationships->delete; |
| 702 |
|
| 668 |
t::lib::Mocks::mock_preference('AnonymousPatron', 0); # back to default |
703 |
t::lib::Mocks::mock_preference('AnonymousPatron', 0); # back to default |
| 669 |
$t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber) |
704 |
$t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber) |
| 670 |
->status_is(204, 'SWAGGER3.2.4') |
705 |
->status_is(204, 'SWAGGER3.2.4') |
| 671 |
->content_is('', 'SWAGGER3.3.4'); |
706 |
->content_is('', 'SWAGGER3.3.4'); |
| 672 |
|
707 |
|
|
|
708 |
my $deleted_patrons = Koha::Old::Patrons->search({ borrowernumber => $patron->borrowernumber }); |
| 709 |
is( $deleted_patrons->count, 1, 'The patron has been moved to the vault' ); |
| 710 |
|
| 673 |
$schema->storage->txn_rollback; |
711 |
$schema->storage->txn_rollback; |
| 674 |
}; |
712 |
}; |
| 675 |
}; |
713 |
}; |
| 676 |
- |
|
|