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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Martin Renvoize 2022-05-03 08:06:41 +01:00 committed by Fridolin Somers
parent 19a2c53ddd
commit cefb82be2c
1 changed files with 12 additions and 63 deletions

View File

@ -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->stash_embed();
my $embed = $c->stash('koha.embed');
$c->render(
status => 200,
json => $c->stash( 'koha.embed' )
);
}
catch {
$c->render(
status => 400,
json => { error => "$_" }
);
};
};
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 {