From cefb82be2cd36e1e1d094f058000ecfdb855a50a Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 3 May 2022 08:06:41 +0100 Subject: [PATCH] Bug 30536: Fix Query.t Unit Test The stash_embed method no longer validates the query so this patch drops the validation tests and instead just focuses on varifying the correct output structure of the stash after the method call. We have not lost validation however, it now happens only once at the OpenAPI level and tests are present in t/db_dependent/api/v1/query.t Signed-off-by: Marcel de Rooy Signed-off-by: Fridolin Somers --- t/Koha/REST/Plugin/Query.t | 75 ++++++-------------------------------- 1 file changed, 12 insertions(+), 63 deletions(-) diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t index 13103f3a29..5a3774599f 100755 --- a/t/Koha/REST/Plugin/Query.t +++ b/t/Koha/REST/Plugin/Query.t @@ -209,50 +209,13 @@ get '/build_query' => sub { get '/stash_embed' => sub { my $c = shift; - try { - $c->stash_embed( - { - spec => { - 'x-koha-embed' => [ - 'checkouts', - 'checkouts.item', - 'library', - 'holds+count' - ] - } - } - ); - - $c->render( - status => 200, - json => $c->stash( 'koha.embed' ) - ); - } - catch { - $c->render( - status => 400, - json => { error => "$_" } - ); - }; -}; + $c->stash_embed(); + my $embed = $c->stash('koha.embed'); -get '/stash_embed_no_spec' => sub { - my $c = shift; - - try { - $c->stash_embed({ spec => {} }); - - $c->render( - status => 200, - json => $c->stash( 'koha.embed' ) - ); - } - catch { - $c->render( - status => 400, - json => { error => "$_" } - ); - }; + $c->render( + status => 200, + json => $embed + ); }; get '/stash_overrides' => sub { @@ -466,38 +429,24 @@ subtest '_build_query_params_from_api' => sub { subtest 'stash_embed() tests' => sub { - plan tests => 15; + plan tests => 8; my $t = Test::Mojo->new; $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item' } ) - ->status_is(200) - ->json_is( { checkouts => { children => { item => {} } } } ); + ->json_is( { checkouts => { children => { item => { } } } } ); $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item,library' } ) - ->status_is(200) ->json_is( { checkouts => { children => { item => {} } }, library => {} } ); $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'holds+count' } ) - ->status_is(200) ->json_is( { holds_count => { is_count => 1 } } ); $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } ) - ->status_is(400) - ->json_is( - { - error => qq{Exception 'Koha::Exceptions::BadParameter' thrown 'Embeding patron is not authorised. Check your x-koha-embed headers or remove it.'\n} - } - ); - - $t->get_ok( '/stash_embed_no_spec' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } ) - ->status_is(400) - ->json_is( - { - error => qq{Exception 'Koha::Exceptions::BadParameter' thrown 'Embedding objects is not allowed on this endpoint.'\n} - } - ); - + ->json_is({ + checkouts => { children => { item => {} } }, + patron => {} + }); }; subtest 'stash_overrides() tests' => sub { -- 2.20.1