3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 # Dummy app for testing the plugin
21 use Mojolicious::Lite;
23 app->log->level('error');
25 plugin 'Koha::REST::Plugin::Query';
29 $c->render( json => undef, status => 200 );
37 firstname => 'Manuel',
38 surname => 'Cohen Arazi'
40 my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($input);
43 filtered_params => $filtered_params,
44 reserved_params => $reserved_params
50 get '/query_full' => sub {
57 firstname => 'Manuel',
58 surname => 'Cohen Arazi'
60 my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($input);
63 filtered_params => $filtered_params,
64 reserved_params => $reserved_params
70 get '/dbic_merge_sorting' => sub {
72 my $attributes = { a => 'a', b => 'b' };
73 $attributes = $c->dbic_merge_sorting(
75 attributes => $attributes,
76 params => { _match => 'exact', _order_by => [ 'uno', '-dos', '+tres', ' cuatro' ] }
79 $c->render( json => $attributes, status => 200 );
84 use Test::More tests => 2;
87 subtest 'extract_reserved_params() tests' => sub {
91 my $t = Test::Mojo->new;
93 $t->get_ok('/query')->status_is(200)
94 ->json_is( '/filtered_params' =>
95 { firstname => 'Manuel', surname => 'Cohen Arazi' } )
96 ->json_is( '/reserved_params' => { _page => 2, _per_page => 3 } );
98 $t->get_ok('/query_full')->status_is(200)
100 '/filtered_params' => {
101 firstname => 'Manuel',
102 surname => 'Cohen Arazi'
105 '/reserved_params' => {
114 subtest 'dbic_merge_sorting() tests' => sub {
118 my $t = Test::Mojo->new;
120 $t->get_ok('/dbic_merge_sorting')->status_is(200)
121 ->json_is( '/a' => 'a', 'Existing values are kept (a)' )
122 ->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is(