From cb54423cdbbe89d20016ba4e5d4de3030c1afe83 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 --- t/Koha/REST/Plugin/Query.t | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 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..6ce7da3 --- /dev/null +++ b/t/Koha/REST/Plugin/Query.t @@ -0,0 +1,79 @@ +#!/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 'generate_dbic_query() 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.7.4