View | Details | Raw Unified | Return to bug 30536
Collapse All | Expand All

(-)a/t/Koha/REST/Plugin/Query.t (-64 / +12 lines)
Lines 209-258 get '/build_query' => sub { Link Here
209
get '/stash_embed' => sub {
209
get '/stash_embed' => sub {
210
    my $c = shift;
210
    my $c = shift;
211
211
212
    try {
212
    $c->stash_embed();
213
        $c->stash_embed(
213
    my $embed = $c->stash('koha.embed');
214
            {
215
                spec => {
216
                    'x-koha-embed' => [
217
                        'checkouts',
218
                        'checkouts.item',
219
                        'library',
220
                        'holds+count'
221
                    ]
222
                }
223
            }
224
        );
225
226
        $c->render(
227
            status => 200,
228
            json   => $c->stash( 'koha.embed' )
229
        );
230
    }
231
    catch {
232
        $c->render(
233
            status => 400,
234
            json   => { error => "$_" }
235
        );
236
    };
237
};
238
214
239
get '/stash_embed_no_spec' => sub {
215
    $c->render(
240
    my $c = shift;
216
        status => 200,
241
217
        json   => $embed
242
    try {
218
    );
243
        $c->stash_embed({ spec => {} });
244
245
        $c->render(
246
            status => 200,
247
            json   => $c->stash( 'koha.embed' )
248
        );
249
    }
250
    catch {
251
        $c->render(
252
            status => 400,
253
            json   => { error => "$_" }
254
        );
255
    };
256
};
219
};
257
220
258
get '/stash_overrides' => sub {
221
get '/stash_overrides' => sub {
Lines 466-503 subtest '_build_query_params_from_api' => sub { Link Here
466
429
467
subtest 'stash_embed() tests' => sub {
430
subtest 'stash_embed() tests' => sub {
468
431
469
    plan tests => 15;
432
    plan tests => 8;
470
433
471
    my $t = Test::Mojo->new;
434
    my $t = Test::Mojo->new;
472
435
473
    $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item' } )
436
    $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item' } )
474
      ->status_is(200)
437
      ->json_is( { checkouts => { children => { item => { } } } } );
475
      ->json_is( { checkouts => { children => { item => {} } } } );
476
438
477
    $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item,library' } )
439
    $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item,library' } )
478
      ->status_is(200)
479
      ->json_is( { checkouts => { children => { item => {} } }, library => {} } );
440
      ->json_is( { checkouts => { children => { item => {} } }, library => {} } );
480
441
481
    $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'holds+count' } )
442
    $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'holds+count' } )
482
      ->status_is(200)
483
      ->json_is( { holds_count => { is_count => 1 } } );
443
      ->json_is( { holds_count => { is_count => 1 } } );
484
444
485
    $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } )
445
    $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } )
486
      ->status_is(400)
446
      ->json_is({
487
      ->json_is(
447
            checkouts => { children => { item => {} } },
488
        {
448
            patron    => {}
489
            error => qq{Exception 'Koha::Exceptions::BadParameter' thrown 'Embeding patron is not authorised. Check your x-koha-embed headers or remove it.'\n}
449
        });
490
        }
491
      );
492
493
    $t->get_ok( '/stash_embed_no_spec' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } )
494
      ->status_is(400)
495
      ->json_is(
496
        {
497
            error => qq{Exception 'Koha::Exceptions::BadParameter' thrown 'Embedding objects is not allowed on this endpoint.'\n}
498
        }
499
      );
500
501
};
450
};
502
451
503
subtest 'stash_overrides() tests' => sub {
452
subtest 'stash_overrides() tests' => sub {
504
- 

Return to bug 30536