From 296c84e0e8ff97bd3bef298ebccc23808a67d6d9 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 7 Nov 2022 12:25:33 +0000 Subject: [PATCH] Bug 26635: (follow-up) Rename av_expand to strings This patch updates the `av_expand` occurences to `strings` to match the change of the return structure of `_strings`. We replace `+av_expand` in the headers with `+strings`, the expected object method name from `api_av_mapping` to `api_strings_mapping` and the internal hash key from `av_expand` to `strings`. Test plan 1) Run the included unit tests.. all should still pass. Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- Koha/Object.pm | 16 +++++++-------- Koha/REST/Plugin/Objects.pm | 12 ++++++------ Koha/REST/Plugin/Query.pm | 8 ++++---- t/Koha/REST/Plugin/Query.t | 22 ++++++++++----------- t/db_dependent/Koha/Object.t | 24 +++++++++++------------ t/db_dependent/Koha/REST/Plugin/Objects.t | 10 +++++----- 6 files changed, 46 insertions(+), 46 deletions(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index fcebdade9a..b4b5717c34 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -558,13 +558,13 @@ sub to_api { $params = defined $params ? {%$params} : {}; # children should be able to handle without - my $embeds = delete $params->{embed}; - my $av_expand = delete $params->{av_expand}; + my $embeds = delete $params->{embed}; + my $strings = delete $params->{strings}; # coded values handling my $avs = {}; - if ( $av_expand and $self->can('api_av_mapping') ) { - $avs = $self->api_av_mapping($params); + if ( $strings and $self->can('api_strings_mapping') ) { + $avs = $self->api_strings_mapping($params); } # Remove forbidden attributes if required (including their coded values) @@ -573,7 +573,7 @@ sub to_api { delete $json_object->{$field} unless any { $_ eq $field } @{ $self->public_read_list }; } - if ( $av_expand ) { + if ( $strings ) { foreach my $field (keys %{$avs}) { delete $avs->{$field} unless any { $_ eq $field } @{ $self->public_read_list }; @@ -606,7 +606,7 @@ sub to_api { } $json_object->{_strings} = $avs - if $av_expand; + if $strings; if ($embeds) { foreach my $embed ( keys %{$embeds} ) { @@ -620,8 +620,8 @@ sub to_api { my $curr = $embed; my $next = $embeds->{$curr}->{children}; - $params->{av_expand} = 1 - if $embeds->{$embed}->{av_expand}; + $params->{strings} = 1 + if $embeds->{$embed}->{strings}; my $children = $self->$curr; diff --git a/Koha/REST/Plugin/Objects.pm b/Koha/REST/Plugin/Objects.pm index ccc0a08942..eba63a4ded 100644 --- a/Koha/REST/Plugin/Objects.pm +++ b/Koha/REST/Plugin/Objects.pm @@ -53,8 +53,8 @@ the requested object. It passes through any embeds if specified. my $attributes = {}; # Look for embeds - my $embed = $c->stash('koha.embed'); - my $av_expand = $c->stash('koha.av_expand'); + my $embed = $c->stash('koha.embed'); + my $strings = $c->stash('koha.strings'); # Generate prefetches for embedded stuff $c->dbic_merge_prefetch( @@ -68,7 +68,7 @@ the requested object. It passes through any embeds if specified. return unless $object; - return $object->to_api({ embed => $embed, av_expand => $av_expand }); + return $object->to_api({ embed => $embed, strings => $strings }); } ); @@ -99,8 +99,8 @@ shouldn't be called twice in it. # Privileged reques? my $is_public = $c->stash('is_public'); # Look for embeds - my $embed = $c->stash('koha.embed'); - my $av_expand = $c->stash('koha.av_expand'); + my $embed = $c->stash('koha.embed'); + my $strings = $c->stash('koha.strings'); # Merge sorting into query attributes $c->dbic_merge_sorting( @@ -205,7 +205,7 @@ shouldn't be called twice in it. } ); - return $objects->to_api({ embed => $embed, public => $is_public, av_expand => $av_expand }); + return $objects->to_api({ embed => $embed, public => $is_public, strings => $strings }); } ); } diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm index f75d284625..56f2e2b0f1 100644 --- a/Koha/REST/Plugin/Query.pm +++ b/Koha/REST/Plugin/Query.pm @@ -242,8 +242,8 @@ Unwraps and stashes the x-koha-embed headers for use later query construction if ($embed_header) { my $THE_embed = {}; foreach my $embed_req ( split /\s*,\s*/, $embed_header ) { - if ( $embed_req eq '+av_expand' ) { # special case - $c->stash( 'koha.av_expand' => 1 ); + if ( $embed_req eq '+strings' ) { # special case + $c->stash( 'koha.strings' => 1 ); } else { _merge_embed( _parse_embed($embed_req), $THE_embed ); } @@ -368,9 +368,9 @@ sub _parse_embed { my $key = $+{relation} . "_count"; $result->{$key} = { is_count => 1 }; } - elsif ( $curr =~ m/^(?.*)\+av_expand/ ) { + elsif ( $curr =~ m/^(?.*)\+strings/ ) { my $key = $+{relation}; - $result->{$key} = { av_expand => 1 }; + $result->{$key} = { strings => 1 }; } else { $result->{$curr} = {}; diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t index 509f4f9ff6..9da2590e48 100755 --- a/t/Koha/REST/Plugin/Query.t +++ b/t/Koha/REST/Plugin/Query.t @@ -210,14 +210,14 @@ get '/stash_embed' => sub { my $c = shift; $c->stash_embed(); - my $embed = $c->stash('koha.embed'); - my $av_expand = $c->stash('koha.av_expand'); + my $embed = $c->stash('koha.embed'); + my $strings = $c->stash('koha.strings'); $c->render( status => 200, json => { - av_expand => $av_expand, - embed => $embed, + strings => $strings, + embed => $embed, } ); }; @@ -452,19 +452,19 @@ subtest 'stash_embed() tests' => sub { patron => {} }); - $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item+av_expand,patron+av_expand' } ) + $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item+strings,patron+strings' } ) ->json_is( '/embed' => { - checkouts => { children => { item => { av_expand => 1 } } }, - patron => { av_expand => 1 } + checkouts => { children => { item => { strings => 1 } } }, + patron => { strings => 1 } }) - ->json_is( '/av_expand' => undef ); + ->json_is( '/strings' => undef ); - $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts+av_expand,checkouts.item,patron,+av_expand' } ) + $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts+strings,checkouts.item,patron,+strings' } ) ->json_is( '/embed' => { - checkouts => { children => { item => { } }, av_expand => 1 }, + checkouts => { children => { item => { } }, strings => 1 }, patron => { } }) - ->json_is( '/av_expand' => 1 ); + ->json_is( '/strings' => 1 ); }; subtest 'stash_overrides() tests' => sub { diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index fd06f7821d..38a6eaf0e4 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -303,7 +303,7 @@ subtest "to_api() tests" => sub { is($biblio_api->{items}->[0]->{holds}->[0]->{hold_id}, $hold->reserve_id, 'Hold matches'); is_deeply($biblio_api->{biblioitem}, $biblio->biblioitem->to_api, 'More than one root'); - my $_str = { + my $_strings = { location => { category => 'ASD', str => 'Estante alto', @@ -311,18 +311,18 @@ subtest "to_api() tests" => sub { } }; - # mock Koha::Item so it implements 'api_av_mapping' + # mock Koha::Item so it implements 'api_strings_mapping' my $item_mock = Test::MockModule->new('Koha::Item'); $item_mock->mock( - 'api_av_mapping', + 'api_strings_mapping', sub { - return $_str; + return $_strings; } ); my $hold_api = $hold->to_api( { - embed => { 'item' => { av_expand => 1 } } + embed => { 'item' => { strings => 1 } } } ); @@ -330,8 +330,8 @@ subtest "to_api() tests" => sub { is( $hold_api->{item}->{item_id}, $item->itemnumber, 'Object embedded correctly' ); is_deeply( $hold_api->{item}->{_strings}, - $_str, - '_str correctly added to nested embed' + $_strings, + '_strings correctly added to nested embed' ); # biblio with no items @@ -475,7 +475,7 @@ subtest "to_api() tests" => sub { my $city_mock = Test::MockModule->new('Koha::City'); $city_mock->mock( - 'api_av_mapping', + 'api_strings_mapping', sub { my ( $self, $params ) = @_; @@ -508,11 +508,11 @@ subtest "to_api() tests" => sub { } ); - my $mobj = $marseille->to_api( { av_expand => 1, public => 1 } ); - my $cobj = $cordoba->to_api( { av_expand => 1, public => 0 } ); + my $mobj = $marseille->to_api( { strings => 1, public => 1 } ); + my $cobj = $cordoba->to_api( { strings => 1, public => 0 } ); - ok( exists $mobj->{_strings}, '_str exists for Marseille' ); - ok( exists $cobj->{_strings}, '_str exists for Córdoba' ); + ok( exists $mobj->{_strings}, '_strings exists for Marseille' ); + ok( exists $cobj->{_strings}, '_strings exists for Córdoba' ); is_deeply( $mobj->{_strings}->{country}, diff --git a/t/db_dependent/Koha/REST/Plugin/Objects.t b/t/db_dependent/Koha/REST/Plugin/Objects.t index 079f9c77c7..3a4832f2f5 100755 --- a/t/db_dependent/Koha/REST/Plugin/Objects.t +++ b/t/db_dependent/Koha/REST/Plugin/Objects.t @@ -673,7 +673,7 @@ subtest 'objects.find helper with expanded authorised values' => sub { my $city_class = Test::MockModule->new('Koha::City'); $city_class->mock( - 'api_av_mapping', + 'api_strings_mapping', sub { my ($self, $params) = @_; use Koha::AuthorisedValues; @@ -714,7 +714,7 @@ subtest 'objects.find helper with expanded authorised values' => sub { } ); - $t->get_ok( '/cities/' . $manuel->id => { 'x-koha-embed' => '+av_expand' } ) + $t->get_ok( '/cities/' . $manuel->id => { 'x-koha-embed' => '+strings' } ) ->status_is(200)->json_is( '/name' => 'Manuel' ) ->json_has('/_strings') ->json_is( '/_strings/country/type' => 'av' ) @@ -725,7 +725,7 @@ subtest 'objects.find helper with expanded authorised values' => sub { ->status_is(200)->json_is( '/name' => 'Manuel' ) ->json_hasnt('/_strings'); - $t->get_ok( '/cities/' . $manuela->id => { 'x-koha-embed' => '+av_expand' } ) + $t->get_ok( '/cities/' . $manuela->id => { 'x-koha-embed' => '+strings' } ) ->status_is(200)->json_is( '/name' => 'Manuela' ) ->json_has('/_strings') ->json_is( '/_strings/country/type' => 'av' ) @@ -786,7 +786,7 @@ subtest 'objects.search helper with expanded authorised values' => sub { my $city_class = Test::MockModule->new('Koha::City'); $city_class->mock( - 'api_av_mapping', + 'api_strings_mapping', sub { my ($self, $params) = @_; use Koha::AuthorisedValues; @@ -829,7 +829,7 @@ subtest 'objects.search helper with expanded authorised values' => sub { ); $t->get_ok( '/cities?name=manuel&_per_page=4&_page=1&_match=starts_with' => - { 'x-koha-embed' => '+av_expand' } )->status_is(200) + { 'x-koha-embed' => '+strings' } )->status_is(200) ->json_has('/0')->json_has('/1')->json_hasnt('/2') ->json_is( '/0/name' => 'Manuel' ) ->json_has('/0/_strings') -- 2.39.5