Bug 24191: Regression tests
This patch adds missing tests for calling objects.search with non-existent column names for sorting, that should be mapped using to_model for that matter. Tests should fail as there's no current use of to_model for building the order_by portion of the query. Sponsored-by: ByWater Solutions Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
704ea1a62e
commit
2a169e94cd
1 changed files with 42 additions and 1 deletions
|
@ -50,6 +50,14 @@ get '/cities_to_model_to_api' => sub {
|
|||
$c->render( status => 200, json => $cities );
|
||||
};
|
||||
|
||||
get '/cities_sorted' => sub {
|
||||
my $c = shift;
|
||||
$c->validation->output($c->req->params->to_hash);
|
||||
my $cities_set = Koha::Cities->new;
|
||||
my $cities = $c->objects->search( $cities_set, \&to_model, \&to_api );
|
||||
$c->render( status => 200, json => $cities );
|
||||
};
|
||||
|
||||
sub to_model {
|
||||
my $params = shift;
|
||||
|
||||
|
@ -71,7 +79,7 @@ sub to_api {
|
|||
}
|
||||
|
||||
# The tests
|
||||
use Test::More tests => 1;
|
||||
use Test::More tests => 2;
|
||||
use Test::Mojo;
|
||||
|
||||
use t::lib::TestBuilder;
|
||||
|
@ -233,3 +241,36 @@ subtest 'objects.search helper' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'objects.search helper, sorting on mapped column' => sub {
|
||||
|
||||
plan tests => 14;
|
||||
|
||||
my $t = Test::Mojo->new;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
# Have complete control over the existing cities to ease testing
|
||||
Koha::Cities->delete;
|
||||
|
||||
$builder->build_object({ class => 'Koha::Cities', value => { city_name => 'A', city_country => 'Argentina' } });
|
||||
$builder->build_object({ class => 'Koha::Cities', value => { city_name => 'B', city_country => 'Argentina' } });
|
||||
|
||||
$t->get_ok('/cities_sorted?_order_by=%2Bnombre&_order_by=+city_country')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_has('/1')
|
||||
->json_hasnt('/2')
|
||||
->json_is('/0/nombre' => 'A')
|
||||
->json_is('/1/nombre' => 'B');
|
||||
|
||||
$t->get_ok('/cities_sorted?_order_by=-nombre')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_has('/1')
|
||||
->json_hasnt('/2')
|
||||
->json_is('/0/nombre' => 'B')
|
||||
->json_is('/1/nombre' => 'A');
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue