Bug 39932: Make Koha::Item->_status return an arrayref

This patch makes the method return an actual array instead of a
comma-separated string. The API spec is adjusted so it also expects an
array in the response.

Tests are adjusted for the new return value.

To test:
1. Apply this patch
2. Run:
   $ ktd --shell
  k$ yarn api:bundle
  k$ prove t/db_dependent/Koha/Item.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Tomas Cohen Arazi 2025-05-19 08:57:27 -03:00 committed by Katrin Fischer
parent d17f6552a1
commit ffab355be0
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 27 additions and 19 deletions

View File

@ -1491,7 +1491,7 @@ sub _status {
push @statuses, 'in_bundle';
}
return join ',', @statuses;
return \@statuses;
}
=head3 additional_attributes

View File

@ -324,7 +324,7 @@ properties:
description: A return claims object if one exists that's unresolved
_status:
type:
- string
- array
- "null"
description: The status of the item
additionalProperties: false
additionalProperties: false

View File

@ -37,7 +37,7 @@ use Koha::Old::Items;
use Koha::Recalls;
use Koha::AuthorisedValues;
use List::MoreUtils qw(all);
use List::MoreUtils qw(all any);
use t::lib::TestBuilder;
use t::lib::Mocks;
@ -46,8 +46,9 @@ use t::lib::Dates;
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
subtest '_status' => sub {
plan tests => 12;
subtest '_status() tests' => sub {
plan tests => 15;
$schema->storage->txn_begin;
@ -66,7 +67,7 @@ subtest '_status' => sub {
AddIssue( $patron, $onloan_item->barcode, dt_from_string );
return $onloan_item;
},
expected_status => 'checked_out',
expected_status => ['checked_out'],
description => 'Checked out status correctly returned',
},
{
@ -78,14 +79,14 @@ subtest '_status' => sub {
);
return $onsite_item;
},
expected_status => 'local_use',
expected_status => ['local_use'],
description => 'Local use status correctly returned',
},
{
setup => sub {
return $item;
},
expected_status => 'available',
expected_status => ['available'],
description => 'Available status correctly returned',
},
{
@ -93,7 +94,7 @@ subtest '_status' => sub {
$item->itemlost(1)->store();
return $item;
},
expected_status => 'lost',
expected_status => ['lost'],
description => 'Lost status correctly returned',
},
{
@ -101,7 +102,7 @@ subtest '_status' => sub {
$item->withdrawn(1)->store();
return $item;
},
expected_status => qr/lost,withdrawn/,
expected_status => [qw(lost withdrawn)],
description => 'Lost and withdrawn status correctly returned',
},
{
@ -109,7 +110,7 @@ subtest '_status' => sub {
$item->damaged(1)->store();
return $item;
},
expected_status => qr/lost,withdrawn,damaged/,
expected_status => [qw(lost withdrawn damaged)],
description => 'Lost, withdrawn, and damaged status correctly returned',
},
{
@ -117,7 +118,7 @@ subtest '_status' => sub {
$item->notforloan(1)->store();
return $item;
},
expected_status => 'not_for_loan',
expected_status => ['not_for_loan'],
description => 'Positive not_for_loan status correctly returned',
},
{
@ -125,7 +126,7 @@ subtest '_status' => sub {
$item->notforloan(-1)->store();
return $item;
},
expected_status => 'not_for_loan',
expected_status => ['not_for_loan'],
description => 'Negative not_for_loan status correctly returned',
},
{
@ -134,7 +135,7 @@ subtest '_status' => sub {
my $notforloan_item = $builder->build_sample_item( { itype => $itemtype->itemtype, } );
return $notforloan_item;
},
expected_status => 'not_for_loan',
expected_status => ['not_for_loan'],
description => 'Item type not_for_loan status correctly returned',
},
{
@ -150,7 +151,7 @@ subtest '_status' => sub {
);
return $onhold_item;
},
expected_status => 'on_hold',
expected_status => ['on_hold'],
description => 'On hold status correctly returned',
},
{
@ -161,7 +162,7 @@ subtest '_status' => sub {
{ biblio => $recalled_item->biblio, item => $recalled_item, patron => $patron } );
return $recalled_item;
},
expected_status => 'recalled',
expected_status => ['recalled'],
description => 'Recalled status correctly returned',
},
{
@ -169,14 +170,21 @@ subtest '_status' => sub {
$item->restricted(1)->store();
return $item;
},
expected_status => 'restricted',
expected_status => ['restricted'],
description => 'Restricted status correctly returned',
},
);
foreach my $test_case (@test_cases) {
my $item = $test_case->{setup}->();
ok( $item->_status() =~ /$test_case->{expected_status}/, $test_case->{description} );
my $expected_statuses = $test_case->{expected_status};
foreach my $expected_status ( @{$expected_statuses} ) {
ok(
( any { $expected_status eq $_ } @{ $item->_status() } ),
$test_case->{description} . " ($expected_status)"
);
}
}
t::lib::Mocks::mock_preference( 'UseRecalls', 0 );