View | Details | Raw Unified | Return to bug 19234
Collapse All | Expand All

(-)a/t/Koha/REST/Plugin/Query.t (-1 / +100 lines)
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(
42
        json => {
43
            filtered_params => $filtered_params,
44
            reserved_params => $reserved_params
45
        },
46
        status => 200
47
    );
48
};
49
50
get '/query_full' => sub {
51
    my $c     = shift;
52
    my $input = {
53
        _match    => 'exact',
54
        _order_by => 'blah',
55
        _page     => 2,
56
        _per_page => 3,
57
        firstname => 'Manuel',
58
        surname   => 'Cohen Arazi'
59
    };
60
    my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($input);
61
    $c->render(
62
        json => {
63
            filtered_params => $filtered_params,
64
            reserved_params => $reserved_params
65
        },
66
        status => 200
67
    );
68
};
69
70
# The tests
71
72
use Test::More tests => 1;
73
use Test::Mojo;
74
75
subtest 'extract_reserved_params() tests' => sub {
76
77
    plan tests => 8;
78
79
    my $t = Test::Mojo->new;
80
81
    $t->get_ok('/query')->status_is(200)
82
      ->json_is( '/filtered_params' =>
83
          { firstname => 'Manuel', surname => 'Cohen Arazi' } )
84
      ->json_is( '/reserved_params' => { _page => 2, _per_page => 3 } );
85
86
    $t->get_ok('/query_full')->status_is(200)
87
      ->json_is(
88
        '/filtered_params' => {
89
            firstname => 'Manuel',
90
            surname   => 'Cohen Arazi'
91
        } )
92
      ->json_is(
93
        '/reserved_params' => {
94
            _page     => 2,
95
            _per_page => 3,
96
            _match    => 'exact',
97
            _order_by => 'blah'
98
        } );
99
100
};

Return to bug 19234