From 00f0780b7f9f007f55b5cd4858e3b8069dc25ba4 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 6 Oct 2022 10:44:59 -0300 Subject: [PATCH] Bug 17170: (QA follow-up) Spec cleanup This patch removes not required (for now) query parameters as we can query using q= on those. They can be added back eventually, if needed. Attributes now match the database as well. Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/SearchFilter.pm | 4 +- Koha/SearchFilter.pm | 12 ---- api/v1/swagger/definitions/search_filter.yaml | 4 +- api/v1/swagger/paths/search_filters.yaml | 25 -------- .../prog/en/modules/admin/search_filters.tt | 4 +- t/db_dependent/api/v1/search_filters.t | 60 ++++++++----------- 6 files changed, 31 insertions(+), 78 deletions(-) diff --git a/Koha/REST/V1/SearchFilter.pm b/Koha/REST/V1/SearchFilter.pm index 05c72e7e9b..cf796a263f 100644 --- a/Koha/REST/V1/SearchFilter.pm +++ b/Koha/REST/V1/SearchFilter.pm @@ -59,9 +59,7 @@ Controller function that handles retrieving a single Koha::AdvancedEditorMacro sub get { my $c = shift->openapi->valid_input or return; - my $filter = Koha::SearchFilters->find({ - id => $c->validation->param('search_filter_id'), - }); + my $filter = Koha::SearchFilters->find( $c->validation->param('search_filter_id') ); unless ($filter) { return $c->render( status => 404, openapi => { error => "Search filter not found" } ); diff --git a/Koha/SearchFilter.pm b/Koha/SearchFilter.pm index 547e89a448..3683a89b28 100644 --- a/Koha/SearchFilter.pm +++ b/Koha/SearchFilter.pm @@ -29,18 +29,6 @@ Koha::SearchFilter - Koha Search filter object class =head2 Class methods -=head3 to_api_mapping - -=cut - -sub to_api_mapping { - return { - id => 'search_filter_id', - query => 'filter_query', - limits => 'filter_limits', - }; -} - =head3 expand_filter my ($expanded_limit, $query_limit) = $filter->expand_filter; diff --git a/api/v1/swagger/definitions/search_filter.yaml b/api/v1/swagger/definitions/search_filter.yaml index a60e3f0ad4..c38f1239f0 100644 --- a/api/v1/swagger/definitions/search_filter.yaml +++ b/api/v1/swagger/definitions/search_filter.yaml @@ -8,12 +8,12 @@ properties: name: description: filter name type: string - filter_query: + query: description: filter query part type: - string - 'null' - filter_limits: + limits: description: filter limits part type: - string diff --git a/api/v1/swagger/paths/search_filters.yaml b/api/v1/swagger/paths/search_filters.yaml index 5aa61e7350..03de8188d6 100644 --- a/api/v1/swagger/paths/search_filters.yaml +++ b/api/v1/swagger/paths/search_filters.yaml @@ -9,31 +9,6 @@ produces: - application/json parameters: - - name: name - in: query - description: Case insensitive search on filter name - required: false - type: string - - name: filter_query - in: query - description: Search on filter query part - required: false - type: string - - name: filter_limits - in: query - description: Search on filter limits - required: false - type: string - - name: opac - in: query - description: Display in OPAC - required: false - type: boolean - - name: staff_client - in: query - description: Display on staff client - required: false - type: boolean - $ref: "../swagger.yaml#/parameters/match" - $ref: "../swagger.yaml#/parameters/order_by" - $ref: "../swagger.yaml#/parameters/page" diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/search_filters.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/search_filters.tt index dce6e7db98..1305177426 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/search_filters.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/search_filters.tt @@ -117,12 +117,12 @@ "orderable": true }, { - "data": "filter_query", + "data": "query", "searchable": true, "orderable": true }, { - "data": "filter_limits", + "data": "limits", "searchable": true, "orderable": true }, diff --git a/t/db_dependent/api/v1/search_filters.t b/t/db_dependent/api/v1/search_filters.t index c0b1bb705a..f442f07edd 100755 --- a/t/db_dependent/api/v1/search_filters.t +++ b/t/db_dependent/api/v1/search_filters.t @@ -33,10 +33,11 @@ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); my $t = Test::Mojo->new('Koha::REST::V1'); -$schema->storage->txn_begin; - subtest 'list() tests' => sub { - plan tests => 10; + + plan tests => 6; + + $schema->storage->txn_begin; Koha::SearchFilters->search()->delete(); @@ -94,34 +95,15 @@ subtest 'list() tests' => sub { ->json_has('/2/search_filter_id') ->json_has('/3/search_filter_id'); - subtest 'query parameters' => sub { - - plan tests => 12; - $t->get_ok("//$userid:$password@/api/v1/search_filters?name=" . $search_filter_2->name) - ->status_is(200) - ->json_is( [ $search_filter_2->to_api ] ); - $t->get_ok("//$userid:$password@/api/v1/search_filters?name=NotAName") - ->status_is(200) - ->json_is( [ ] ); - $t->get_ok("//$userid:$password@/api/v1/search_filters?filter_query=kw:any") - ->status_is(200) - ->json_is( [ $search_filter_3->to_api ] ); - $t->get_ok("//$userid:$password@/api/v1/search_filters?filter_limits=mc-itype,phr:BK") - ->status_is(200) - ->json_is( [ $search_filter_1->to_api, $search_filter_2->to_api ] ); - }; - - # Warn on unsupported query parameter - $t->get_ok( "//$userid:$password@/api/v1/search_filters?filter_blah=blah" ) - ->status_is(400) - ->json_is( [{ path => '/query/filter_blah', message => 'Malformed query string'}] ); - + $schema->storage->txn_rollback; }; subtest 'get() tests' => sub { plan tests => 9; + $schema->storage->txn_begin; + my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 3 } @@ -150,12 +132,15 @@ subtest 'get() tests' => sub { ->status_is( 401, 'Cannot search filters without permission' ) ->json_is( '/error' => 'Authentication failure.' ); + $schema->storage->txn_rollback; }; subtest 'add() tests' => sub { plan tests => 17; + $schema->storage->txn_begin; + my $authorized_patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 } @@ -231,11 +216,15 @@ subtest 'add() tests' => sub { ] ); + $schema->storage->txn_rollback; }; subtest 'update() tests' => sub { + plan tests => 15; + $schema->storage->txn_begin; + my $authorized_patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 } @@ -271,18 +260,18 @@ subtest 'update() tests' => sub { ->status_is(403); my $search_filter_update = { - name => "Filter update", - filter_query => "ti:The hobbit", - filter_limits => "mc-ccode:fantasy", + name => "Filter update", + query => "ti:The hobbit", + limits => "mc-ccode:fantasy", }; my $test = $t->put_ok( "//$auth_userid:$password@/api/v1/search_filters/$search_filter_id" => json => $search_filter_update ) ->status_is(200, 'Authorized user can update a macro') ->json_is( '/search_filter_id' => $search_filter_id, 'We get back the id' ) - ->json_is( '/name' => $search_filter_update->{name}, 'We get back the name' ) - ->json_is( '/filter_query' => $search_filter_update->{filter_query}, 'We get back our query' ) - ->json_is( '/filter_limits' => $search_filter_update->{filter_limits}, 'We get back our limits' ) - ->json_is( '/opac' => 1, 'We get back our opac visibility unchanged' ) + ->json_is( '/name' => $search_filter_update->{name}, 'We get back the name' ) + ->json_is( '/query' => $search_filter_update->{query}, 'We get back our query' ) + ->json_is( '/limits' => $search_filter_update->{limits}, 'We get back our limits' ) + ->json_is( '/opac' => 1, 'We get back our opac visibility unchanged' ) ->json_is( '/staff_client' => 1, 'We get back our staff client visibility unchanged' ); # Authorized attempt to write invalid data @@ -307,11 +296,15 @@ subtest 'update() tests' => sub { $t->put_ok("//$auth_userid:$password@/api/v1/search_filters/$non_existent_code" => json => $search_filter_update) ->status_is(404); + $schema->storage->txn_rollback; }; subtest 'delete() tests' => sub { + plan tests => 4; + $schema->storage->txn_begin; + my $authorized_patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 } @@ -348,6 +341,5 @@ subtest 'delete() tests' => sub { $t->delete_ok( "//$auth_userid:$password@/api/v1/search_filters/$search_filter_id") ->status_is( 204, 'Can delete search filter with permission'); + $schema->storage->txn_rollback; }; - -$schema->storage->txn_rollback; -- 2.39.5