From 6caa8dfc570ccaee98fa78dc32a9316baa31995b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 23 Jun 2020 10:35:54 -0300 Subject: [PATCH] [19.11.x] Bug 25662: (follow-up) Add tests for the wrong patron_id added behaviour This patch adds trivial tests for the new error (400) raised when the passed patron_id doesn't exist. To test: 1. Run: $ kshell k$ prove t/db_dependent/api/v1/holds.t => SUCCESS: Tests pass! 2. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/api/v1/holds.t | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index ceadeae6267..c169b31fc11 100644 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -177,7 +177,7 @@ subtest "Test endpoints without permission" => sub { subtest "Test endpoints with permission" => sub { - plan tests => 44; + plan tests => 47; $t->get_ok( "//$userid_1:$password@/api/v1/holds" ) ->status_is(200) @@ -245,6 +245,20 @@ subtest "Test endpoints with permission" => sub { $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) ->status_is(403) ->json_like('/error', qr/itemAlreadyOnHold/); + + my $to_delete_patron = $builder->build_object({ class => 'Koha::Patrons' }); + my $deleted_patron_id = $to_delete_patron->borrowernumber; + $to_delete_patron->delete; + + my $tmp_patron_id = $post_data->{patron_id}; + $post_data->{patron_id} = $deleted_patron_id; + $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) + ->status_is(400) + ->json_is( { error => 'patron_id not found' } ); + + # Restore the original patron_id as it is expected by the next subtest + # FIXME: this tests need to be rewritten from scratch + $post_data->{patron_id} = $tmp_patron_id; }; subtest 'Reserves with itemtype' => sub { -- 2.27.0