From 28640298824e1c418595a433a6856ce53afdd51a Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Thu, 12 Mar 2020 18:47:40 -0300 Subject: [PATCH] Bug 24830: Add tests Signed-off-by: Tomas Cohen Arazi --- t/Koha/REST/Plugin/Query.t | 63 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t index 0ddd6fcb0a..8a275774da 100644 --- a/t/Koha/REST/Plugin/Query.t +++ b/t/Koha/REST/Plugin/Query.t @@ -24,6 +24,7 @@ use Try::Tiny; use Koha::Cities; use Koha::Holds; use Koha::Biblios; +use Koha::Patron::Relationship; app->log->level('error'); @@ -135,6 +136,50 @@ get '/dbic_merge_prefetch' => sub { $c->render( json => $attributes, status => 200 ); }; +get '/dbic_merge_prefetch_recursive' => sub { + my $c = shift; + my $attributes = {}; + my $result_set = Koha::Patron::Relationship->new; + $c->stash('koha.embed', { + "guarantee" => { + "children" => { + "article_requests" => {}, + "housebound_profile" => { + "children" => { + "housebound_visits" => {} + } + }, + "housebound_role" => {} + } + } + }); + + $c->dbic_merge_prefetch({ + attributes => $attributes, + result_set => $result_set + }); + + $c->render( json => $attributes, status => 200 ); +}; + +get '/dbic_merge_prefetch_count' => sub { + my $c = shift; + my $attributes = {}; + my $result_set = Koha::Patron::Relationship->new; + $c->stash('koha.embed', { + "guarantee_count" => { + "is_count" => 1 + } + }); + + $c->dbic_merge_prefetch({ + attributes => $attributes, + result_set => $result_set + }); + + $c->render( json => $attributes, status => 200 ); +}; + get '/merge_q_params' => sub { my $c = shift; my $filtered_params = {'biblio_id' => 1}; @@ -298,13 +343,25 @@ subtest 'dbic_merge_sorting() tests' => sub { }; subtest '/dbic_merge_prefetch' => sub { - plan tests => 4; + plan tests => 10; my $t = Test::Mojo->new; $t->get_ok('/dbic_merge_prefetch')->status_is(200) - ->json_like( '/prefetch/0' => qr/item|biblio/ ) - ->json_like( '/prefetch/1' => qr/item|biblio/ ); + ->json_is( '/prefetch/0' => 'biblio' ) + ->json_is( '/prefetch/1' => 'item' ); + + $t->get_ok('/dbic_merge_prefetch_recursive')->status_is(200) + ->json_is('/prefetch/0' => { + guarantee => [ + 'article_requests', + {housebound_profile => 'housebound_visits'}, + 'housebound_role' + ] + }); + + $t->get_ok('/dbic_merge_prefetch_count')->status_is(200) + ->json_is('/prefetch/0' => 'guarantee'); }; subtest '/merge_q_params' => sub { -- 2.25.1