Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
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. |
9 |
# |
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. |
14 |
# |
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>. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
# Dummy app for testing the plugin |
21 |
use Mojolicious::Lite; |
22 |
|
23 |
app->log->level('error'); |
24 |
|
25 |
plugin 'Koha::REST::Plugin::Query'; |
26 |
|
27 |
get '/empty' => sub { |
28 |
my $c = shift; |
29 |
$c->render( json => undef, status => 200 ); |
30 |
}; |
31 |
|
32 |
get '/query' => sub { |
33 |
my $c = shift; |
34 |
my $input = { |
35 |
_page => 2, |
36 |
_per_page => 3, |
37 |
firstname => 'Manuel', |
38 |
surname => 'Cohen Arazi' |
39 |
}; |
40 |
my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($input); |
41 |
$c->render( json => { filtered_params => $filtered_params, reserved_params => $reserved_params }, status => 200 ); |
42 |
}; |
43 |
|
44 |
get '/query_full' => sub { |
45 |
my $c = shift; |
46 |
my $input = { |
47 |
_match => 'exact', |
48 |
_order_by => 'blah', |
49 |
_page => 2, |
50 |
_per_page => 3, |
51 |
firstname => 'Manuel', |
52 |
surname => 'Cohen Arazi' |
53 |
}; |
54 |
my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($input); |
55 |
$c->render( json => { filtered_params => $filtered_params, reserved_params => $reserved_params }, status => 200 ); |
56 |
}; |
57 |
|
58 |
# The tests |
59 |
|
60 |
use Test::More tests => 1; |
61 |
use Test::Mojo; |
62 |
|
63 |
subtest 'generate_dbic_query() tests' => sub { |
64 |
|
65 |
plan tests => 8; |
66 |
|
67 |
my $t = Test::Mojo->new; |
68 |
|
69 |
$t->get_ok('/query') |
70 |
->status_is(200) |
71 |
->json_is( '/filtered_params' => { firstname => 'Manuel', surname => 'Cohen Arazi' } ) |
72 |
->json_is( '/reserved_params' => { _page => 2, _per_page => 3 } ); |
73 |
|
74 |
$t->get_ok('/query_full') |
75 |
->status_is(200) |
76 |
->json_is( '/filtered_params' => { firstname => 'Manuel', surname => 'Cohen Arazi' } ) |
77 |
->json_is( '/reserved_params' => { _page => 2, _per_page => 3, _match => 'exact', _order_by => 'blah' } ); |
78 |
|
79 |
}; |