From 5fd7af62457b406cc8bbf239d7d4b59d84de0c3b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 30 Apr 2025 21:08:02 +0200 Subject: [PATCH] Bug 38010: Add tests for DELETE vendors/{vendor_id} Signed-off-by: Jonathan Druart --- t/db_dependent/api/v1/acquisitions_vendors.t | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/acquisitions_vendors.t b/t/db_dependent/api/v1/acquisitions_vendors.t index 749ace26b71..9be30b29c4c 100755 --- a/t/db_dependent/api/v1/acquisitions_vendors.t +++ b/t/db_dependent/api/v1/acquisitions_vendors.t @@ -398,7 +398,7 @@ subtest 'update() tests' => sub { subtest 'delete() tests' => sub { - plan tests => 7; + plan tests => 16; $schema->storage->txn_begin; @@ -426,6 +426,25 @@ subtest 'delete() tests' => sub { # Unauthorized attempt to delete $t->delete_ok( "//$unauth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is(403); + my $subscription = + $builder->build_object( { class => 'Koha::Subscriptions', value => { aqbooksellerid => $vendor->id } } ); + $t->delete_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id ) + ->status_is( 409, 'REST3.2.4' ) + ->json_is( '/error' => 'Vendor cannot be deleted with existing baskets, subscriptions or invoices' ); + $subscription->delete; + my $basket = + $builder->build_object( { class => 'Koha::Acquisition::Baskets', value => { booksellerid => $vendor->id } } ); + $t->delete_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id ) + ->status_is( 409, 'REST3.2.4' ) + ->json_is( '/error' => 'Vendor cannot be deleted with existing baskets, subscriptions or invoices' ); + $basket->delete; + my $invoice = + $builder->build_object( { class => 'Koha::Acquisition::Invoices', value => { booksellerid => $vendor->id } } ); + $t->delete_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id ) + ->status_is( 409, 'REST3.2.4' ) + ->json_is( '/error' => 'Vendor cannot be deleted with existing baskets, subscriptions or invoices' ); + $invoice->delete; + $t->delete_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id ) ->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' ); -- 2.34.1