Bug 29018: Regression tests
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
(cherry picked from commit 493db07948)
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
This commit is contained in:
parent
2b19368e1c
commit
c16e8c8174
|
|
@ -27,6 +27,7 @@ use t::lib::Dates;
|
|||
|
||||
use C4::Auth;
|
||||
use Koha::Database;
|
||||
use Koha::Old::Patrons;
|
||||
use Koha::Patron::Debarments qw/AddDebarment/;
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
|
|
@ -418,7 +419,7 @@ subtest 'delete() tests' => sub {
|
|||
$schema->storage->txn_rollback;
|
||||
|
||||
subtest 'librarian access test' => sub {
|
||||
plan tests => 8;
|
||||
plan tests => 18;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
|
@ -443,11 +444,48 @@ subtest 'delete() tests' => sub {
|
|||
->status_is(403, 'Anonymous patron cannot be deleted')
|
||||
->json_is( { error => 'Anonymous patron cannot be deleted' } );
|
||||
|
||||
t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
|
||||
|
||||
my $checkout = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Checkouts',
|
||||
value => { borrowernumber => $patron->borrowernumber }
|
||||
}
|
||||
);
|
||||
my $debit = $patron->account->add_debit({ amount => 10, interface => 'intranet', type => 'MANUAL' });
|
||||
my $guarantee = $builder->build_object({ class => 'Koha::Patrons' });
|
||||
|
||||
$guarantee->add_guarantor({ guarantor_id => $patron->id, relationship => 'parent' });
|
||||
|
||||
$t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber)
|
||||
->status_is(409, 'Patron with checkouts cannot be deleted')
|
||||
->json_is( { error => 'Pending checkouts prevent deletion' } );
|
||||
|
||||
# Make sure it has no pending checkouts
|
||||
$checkout->delete;
|
||||
|
||||
$t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber)
|
||||
->status_is(409, 'Patron with debt cannot be deleted')
|
||||
->json_is( { error => 'Pending debts prevent deletion' } );
|
||||
|
||||
# Make sure it has no debt
|
||||
$patron->account->pay({ amount => 10, debits => [ $debit ] });
|
||||
|
||||
$t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber)
|
||||
->status_is(409, 'Patron with guarantees cannot be deleted')
|
||||
->json_is( { error => 'Patron is a guarantor and it prevents deletion' } );
|
||||
|
||||
# Remove guarantee
|
||||
$patron->guarantee_relationships->delete;
|
||||
|
||||
t::lib::Mocks::mock_preference('AnonymousPatron', 0); # back to default
|
||||
$t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber)
|
||||
->status_is(204, 'SWAGGER3.2.4')
|
||||
->content_is('', 'SWAGGER3.3.4');
|
||||
|
||||
my $deleted_patrons = Koha::Old::Patrons->search({ borrowernumber => $patron->borrowernumber });
|
||||
is( $deleted_patrons->count, 1, 'The patron has been moved to the vault' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue