From 05f0604d609c180070207f5608b256639e2e2ccb Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 30 Oct 2023 11:08:15 -0300 Subject: [PATCH] Bug 34008: (QA follow-up) 'item_type_id' should be used Signed-off-by: Tomas Cohen Arazi --- Koha/ItemType.pm | 8 +++----- Koha/REST/V1/ItemTypes.pm | 8 +++----- api/v1/swagger/definitions/item_type.yaml | 4 ++-- t/db_dependent/api/v1/item_types.t | 7 +++---- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index 200ac166ea..3aed3ec81f 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -221,14 +221,12 @@ on the API. =cut sub to_api_mapping { - return { 'itemtype' => 'item_type' }; + return { 'itemtype' => 'item_type_id' }; } -sub from_api_mapping { - return { 'item_type' => 'itemtype' }; -} +=head2 Internal methods -=head3 type +=head3 _type =cut diff --git a/Koha/REST/V1/ItemTypes.pm b/Koha/REST/V1/ItemTypes.pm index 91de0c4d0f..497ec4c171 100644 --- a/Koha/REST/V1/ItemTypes.pm +++ b/Koha/REST/V1/ItemTypes.pm @@ -21,7 +21,7 @@ use Mojo::Base 'Mojolicious::Controller'; use Koha::ItemTypes; -use Try::Tiny; +use Try::Tiny qw(catch try); =head1 API @@ -35,14 +35,12 @@ sub list { my $c = shift->openapi->valid_input or return; return try { - my $itemtypes_set = Koha::ItemTypes->new; - my $itemtypes = $c->objects->search( $itemtypes_set ); + my $item_types = $c->objects->search( Koha::ItemTypes->new ); - return $c->render( status => 200, openapi => $itemtypes ); + return $c->render( status => 200, openapi => $item_types ); } catch { $c->unhandled_exception($_); }; - } 1; diff --git a/api/v1/swagger/definitions/item_type.yaml b/api/v1/swagger/definitions/item_type.yaml index 6023869aa4..789fe5fcd9 100644 --- a/api/v1/swagger/definitions/item_type.yaml +++ b/api/v1/swagger/definitions/item_type.yaml @@ -1,7 +1,7 @@ --- type: object properties: - item_type: + item_type_id: type: string description: Unique key, a code associated with the item type readOnly: true @@ -93,4 +93,4 @@ properties: additionalProperties: false required: - - item_type + - item_type_id diff --git a/t/db_dependent/api/v1/item_types.t b/t/db_dependent/api/v1/item_types.t index d45208ccfb..c83c84d12b 100755 --- a/t/db_dependent/api/v1/item_types.t +++ b/t/db_dependent/api/v1/item_types.t @@ -32,7 +32,7 @@ my $builder = t::lib::TestBuilder->new; my $t = Test::Mojo->new('Koha::REST::V1'); t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); -subtest 'list_item_types() tests' => sub { +subtest 'list() tests' => sub { plan tests => 12; @@ -109,11 +109,10 @@ subtest 'list_item_types() tests' => sub { my $unauth_userid = $patron->userid; ## Authorized user tests - # No category, 404 expected $t->get_ok("//$userid:$password@/api/v1/item_types")->status_is(200)->json_has('/0'); for my $json ( @{ $t->tx->res->json } ) { - if ( $json->{item_type} eq 'TEST_IT' ) { + if ( $json->{item_type_id} eq 'TEST_IT' ) { is( $json->{description}, 'Test item type' ); ok( !exists $json->{translated_descriptions} ); } @@ -123,7 +122,7 @@ subtest 'list_item_types() tests' => sub { ->status_is(200)->json_has('/0'); for my $json ( @{ $t->tx->res->json } ) { - if ( $json->{item_type} eq 'TEST_IT' ) { + if ( $json->{item_type_id} eq 'TEST_IT' ) { is( $json->{description}, 'Test item type' ); is_deeply( $json->{translated_descriptions}, -- 2.39.5