@@ -, +, @@ --- t/Koha/REST/Plugin/Query.t | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 t/Koha/REST/Plugin/Query.t --- a/t/Koha/REST/Plugin/Query.t +++ a/t/Koha/REST/Plugin/Query.t @@ -0,0 +1,81 @@ +#!/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 ( $filter, $attributes ) = $c->generate_dbic_query($input); + $c->render( json => { filter => $filter, attributes => $attributes }, status => 200 ); +}; + +get '/query_exact' => sub { + my $c = shift; + my $input = { + page => 2, + per_page => 3, + firstname => 'Manuel', + surname => 'Cohen Arazi', + _exact_match => 1 + }; + my ( $filter, $attributes ) = $c->generate_dbic_query($input); + $c->render( json => { filter => $filter, attributes => $attributes }, 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( '/attributes' => { page => 2, rows => 3 } ) + ->json_is( '/filter' => { firstname => { like => 'Manuel%' }, surname => { like => 'Cohen Arazi%' } } ); + + $t->get_ok('/query_exact') + ->status_is( 200 ) + ->json_is( '/attributes' => { page => 2, rows => 3 } ) + ->json_is( '/filter' => { firstname => 'Manuel' , surname => 'Cohen Arazi' } ); + + # use Data::Printer colored => 1; + # p($t->tx->res); +}; --