From 919af45a0264b8bf065f91711d257635fe409a7d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 1 Sep 2017 11:52:29 -0300 Subject: [PATCH] Bug 19234: Unit tests for query parameters handling helpers This patch adds unit tests for the new query parameters handling Mojo plugin. Sponsored-by: Camden County Sponsored-by: ByWater Solutions Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall --- t/Koha/REST/Plugin/Query.t | 100 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 t/Koha/REST/Plugin/Query.t diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t new file mode 100644 index 0000000..8270dc0 --- /dev/null +++ b/t/Koha/REST/Plugin/Query.t @@ -0,0 +1,100 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +# Dummy app for testing the plugin +use Mojolicious::Lite; + +app->log->level('error'); + +plugin 'Koha::REST::Plugin::Query'; + +get '/empty' => sub { + my $c = shift; + $c->render( json => undef, status => 200 ); +}; + +get '/query' => sub { + my $c = shift; + my $input = { + _page => 2, + _per_page => 3, + firstname => 'Manuel', + surname => 'Cohen Arazi' + }; + my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($input); + $c->render( + json => { + filtered_params => $filtered_params, + reserved_params => $reserved_params + }, + status => 200 + ); +}; + +get '/query_full' => sub { + my $c = shift; + my $input = { + _match => 'exact', + _order_by => 'blah', + _page => 2, + _per_page => 3, + firstname => 'Manuel', + surname => 'Cohen Arazi' + }; + my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($input); + $c->render( + json => { + filtered_params => $filtered_params, + reserved_params => $reserved_params + }, + status => 200 + ); +}; + +# The tests + +use Test::More tests => 1; +use Test::Mojo; + +subtest 'extract_reserved_params() tests' => sub { + + plan tests => 8; + + my $t = Test::Mojo->new; + + $t->get_ok('/query')->status_is(200) + ->json_is( '/filtered_params' => + { firstname => 'Manuel', surname => 'Cohen Arazi' } ) + ->json_is( '/reserved_params' => { _page => 2, _per_page => 3 } ); + + $t->get_ok('/query_full')->status_is(200) + ->json_is( + '/filtered_params' => { + firstname => 'Manuel', + surname => 'Cohen Arazi' + } ) + ->json_is( + '/reserved_params' => { + _page => 2, + _per_page => 3, + _match => 'exact', + _order_by => 'blah' + } ); + +}; -- 2.10.2