From 66466e5d8669e00e98ecde507e90f3c1e226ac34 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 29 Apr 2024 15:53:01 +0100 Subject: [PATCH] Bug 36120: (QA follow-up) Fix /biblios.t unit test This patch adds some mock data for pickup_items getting included in the pickup locations response. Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- Koha/REST/V1/Biblios.pm | 11 ++++++++++- t/db_dependent/api/v1/biblios.t | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index 44aabc9d29..1c15e8ec25 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -530,7 +530,16 @@ sub pickup_locations { my $pickup_locations = $c->objects->search($pl_set); @response = map { $_->{needs_override} = Mojo::JSON->false; $_; } @{$pickup_locations}; } - @response = map { $_->{pickup_items} = $pl_set->{_pickup_location_items}->{ $_->{library_id} }; $_; } @response; + @response = map { + if ( exists $pl_set->{_pickup_location_items}->{ $_->{library_id} } + && ref $pl_set->{_pickup_location_items}->{ $_->{library_id} } eq 'ARRAY' ) + { + $_->{pickup_items} = $pl_set->{_pickup_location_items}->{ $_->{library_id} }; + } else { + $_->{pickup_items} = []; + } + $_; + } @response; return $c->render( status => 200, diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t index a5d0f66dcb..c10bae833e 100755 --- a/t/db_dependent/api/v1/biblios.t +++ b/t/db_dependent/api/v1/biblios.t @@ -475,6 +475,10 @@ subtest 'pickup_locations() tests' => sub { $library_2_api->{needs_override} = Mojo::JSON->false; $library_3_api->{needs_override} = Mojo::JSON->true; + $library_1_api->{pickup_items} = []; + $library_2_api->{pickup_items} = []; + $library_3_api->{pickup_items} = []; + my $patron = $builder->build_object( { class => 'Koha::Patrons', @@ -540,6 +544,7 @@ subtest 'pickup_locations() tests' => sub { my $library_5_api = $library_5->to_api(); $library_5_api->{needs_override} = Mojo::JSON->true; + $library_5_api->{pickup_items} = []; $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->id -- 2.39.5