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

(-)a/t/db_dependent/api/v1/biblios.t (-2 / +85 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 4;
20
use Test::More tests => 5;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Mojo;
22
use Test::Mojo;
23
use Test::Warn;
23
use Test::Warn;
Lines 329-331 subtest 'get_public() tests' => sub { Link Here
329
329
330
    $schema->storage->txn_rollback;
330
    $schema->storage->txn_rollback;
331
};
331
};
332
- 
332
333
subtest 'get_items_public() tests' => sub {
334
335
    plan tests => 15;
336
337
    $schema->storage->txn_begin;
338
339
    my $override_hidden_items = 0;
340
341
    my $mocked_category = Test::MockModule->new('Koha::Patron::Category');
342
    $mocked_category->mock(
343
        'override_hidden_items',
344
        sub {
345
            return $override_hidden_items;
346
        }
347
    );
348
349
    my $rules = undef;
350
351
    my $mocked_context = Test::MockModule->new('C4::Context');
352
    $mocked_context->mock(
353
        'yaml_preference',
354
        sub {
355
            return $rules;
356
        }
357
    );
358
359
    my $patron   = $builder->build_object( { class => 'Koha::Patrons' } );
360
    my $password = 'thePassword123';
361
    $patron->set_password( { password => $password, skip_validation => 1 } );
362
    $patron->discard_changes;
363
    my $userid = $patron->userid;
364
365
    my $biblio = $builder->build_sample_biblio();
366
367
    $t->get_ok(
368
        "//$userid:$password@/api/v1/public/biblios/" . $biblio->id . "/items" )
369
      ->status_is(200)->json_is( '' => [], 'No items on the biblio' );
370
371
    my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->id } );
372
    my $item_2 = $builder->build_sample_item(
373
        { biblionumber => $biblio->id, withdrawn => 1 } );
374
375
    $t->get_ok( "//$userid:$password@/api/v1/public/biblios/"
376
          . $biblio->biblionumber
377
          . "/items" )->status_is(200)->json_is(
378
        '' => [
379
            $item_1->to_api( { public => 1 } ),
380
            $item_2->to_api( { public => 1 } )
381
        ],
382
        'The items are returned'
383
          );
384
385
    $rules = { withdrawn => ['1'] };
386
387
    $t->get_ok( "//$userid:$password@/api/v1/public/biblios/"
388
          . $biblio->biblionumber
389
          . "/items" )->status_is(200)->json_is(
390
        '' => [ $item_1->to_api( { public => 1 } ) ],
391
        'The items are returned, hidden one is not returned'
392
          );
393
394
    $t->get_ok( "/api/v1/public/biblios/"
395
          . $biblio->biblionumber
396
          . "/items" )->status_is(200)->json_is(
397
        '' => [ $item_1->to_api( { public => 1 } ) ],
398
        'Anonymous user, items are returned, hidden one is not returned'
399
          );
400
401
402
    $override_hidden_items = 1;
403
404
    $t->get_ok( "//$userid:$password@/api/v1/public/biblios/"
405
          . $biblio->biblionumber
406
          . "/items" )->status_is(200)->json_is(
407
        '' => [
408
            $item_1->to_api( { public => 1 } ),
409
            $item_2->to_api( { public => 1 } )
410
        ],
411
        'The items are returned, the patron category has an override'
412
          );
413
414
    $schema->storage->txn_rollback;
415
};

Return to bug 27358