Bug 17170: (QA follow-up) Spec cleanup
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 6 Oct 2022 13:44:59 +0000 (10:44 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 21 Oct 2022 14:15:22 +0000 (11:15 -0300)
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 <tomascohen@theke.io>
Koha/REST/V1/SearchFilter.pm
Koha/SearchFilter.pm
api/v1/swagger/definitions/search_filter.yaml
api/v1/swagger/paths/search_filters.yaml
koha-tmpl/intranet-tmpl/prog/en/modules/admin/search_filters.tt
t/db_dependent/api/v1/search_filters.t

index 05c72e7..cf796a2 100644 (file)
@@ -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" } );
index 547e89a..3683a89 100644 (file)
@@ -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;
index a60e3f0..c38f123 100644 (file)
@@ -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
index 5aa61e7..03de818 100644 (file)
@@ -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"
index dce6e7d..1305177 100644 (file)
                         "orderable": true
                     },
                     {
-                        "data": "filter_query",
+                        "data": "query",
                         "searchable": true,
                         "orderable": true
                     },
                     {
-                        "data": "filter_limits",
+                        "data": "limits",
                         "searchable": true,
                         "orderable": true
                     },
index c0b1bb7..f442f07 100755 (executable)
@@ -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;