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

(-)a/Koha/REST/V1/Biblios.pm (-11 / +7 lines)
Lines 337-347 sub pickup_locations { Link Here
337
337
338
    return try {
338
    return try {
339
339
340
        my $ps_set = $biblio->pickup_locations( { patron => $patron } );
340
        my $pl_set = $biblio->pickup_locations( { patron => $patron } );
341
341
342
        my $pickup_locations = $c->objects->search( $ps_set );
343
        my @response = ();
342
        my @response = ();
344
345
        if ( C4::Context->preference('AllowHoldPolicyOverride') ) {
343
        if ( C4::Context->preference('AllowHoldPolicyOverride') ) {
346
344
347
            my $libraries_rs = Koha::Libraries->search( { pickup_location => 1 } );
345
            my $libraries_rs = Koha::Libraries->search( { pickup_location => 1 } );
Lines 350-370 sub pickup_locations { Link Here
350
            @response = map {
348
            @response = map {
351
                my $library = $_;
349
                my $library = $_;
352
                $library->{needs_override} = (
350
                $library->{needs_override} = (
353
                    any { $_->{library_id} eq $library->{library_id} }
351
                    any { $_->branchcode eq $library->{library_id} }
354
                    @{$pickup_locations}
352
                    @{$pl_set->as_list}
355
                  )
353
                  )
356
                  ? Mojo::JSON->false
354
                  ? Mojo::JSON->false
357
                  : Mojo::JSON->true;
355
                  : Mojo::JSON->true;
358
                $library;
356
                $library;
359
            } @{$libraries};
357
            } @{$libraries};
360
361
            return $c->render(
362
                status  => 200,
363
                openapi => \@response
364
            );
365
        }
358
        }
359
        else {
366
360
367
        @response = map { $_->{needs_override} = Mojo::JSON->false; $_; } @{$pickup_locations};
361
            my $pickup_locations = $c->objects->search($pl_set);
362
            @response = map { $_->{needs_override} = Mojo::JSON->false; $_; } @{$pickup_locations};
363
        }
368
364
369
        return $c->render(
365
        return $c->render(
370
            status  => 200,
366
            status  => 200,
(-)a/t/db_dependent/api/v1/biblios.t (-2 / +43 lines)
Lines 383-389 subtest 'get_public() tests' => sub { Link Here
383
383
384
subtest 'pickup_locations() tests' => sub {
384
subtest 'pickup_locations() tests' => sub {
385
385
386
    plan tests => 15;
386
    plan tests => 16;
387
387
388
    $schema->storage->txn_begin;
388
    $schema->storage->txn_begin;
389
389
Lines 476-481 subtest 'pickup_locations() tests' => sub { Link Here
476
          . "patron_id=" . $patron->id . "&_order_by=marc_org_code" )
476
          . "patron_id=" . $patron->id . "&_order_by=marc_org_code" )
477
      ->json_is( [ $library_1_api, $library_2_api, $library_3_api, $library_5_api ] );
477
      ->json_is( [ $library_1_api, $library_2_api, $library_3_api, $library_5_api ] );
478
478
479
    subtest 'Pagination and AllowHoldPolicyOverride tests' => sub {
480
481
        plan tests => 27;
482
483
        t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 );
484
485
        $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->id . "/pickup_locations?" . "patron_id=" . $patron->id . "&_order_by=marc_org_code" . "&_per_page=1" )
486
          ->json_is( [$library_1_api] )
487
          ->header_is( 'X-Total-Count', '4', '4 is the count for libraries with pickup_location=1' )
488
          ->header_is( 'X-Base-Total-Count', '4', '4 is the count for libraries with pickup_location=1' )
489
          ->header_unlike( 'Link', qr|rel="prev"| )
490
          ->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1.*)>\; rel="next"# )
491
          ->header_like( 'Link', qr#(_per_page=1.*\&_page=1.*|_page=1.*\&_per_page=1).*>\; rel="first"# )
492
          ->header_like( 'Link', qr#(_per_page=1.*\&_page=4.*|_page=4.*\&_per_page=1).*>\; rel="last"# );
493
494
        $t->get_ok( "//$userid:$password@/api/v1/biblios/"
495
              . $biblio->id
496
              . "/pickup_locations?"
497
              . "patron_id="
498
              . $patron->id
499
              . "&_order_by=marc_org_code"
500
              . "&_per_page=1&_page=3" )    # force the needs_override=1 check
501
          ->json_is( [$library_3_api] )
502
          ->header_is( 'X-Total-Count', '4', '4 is the count for libraries with pickup_location=1' )
503
          ->header_is( 'X-Base-Total-Count', '4', '4 is the count for libraries with pickup_location=1' )
504
          ->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1.*)>\; rel="prev"# )
505
          ->header_like( 'Link', qr#(_per_page=1.*\&_page=4.*|_page=4.*\&_per_page=1.*)>\; rel="next"# )
506
          ->header_like( 'Link', qr#(_per_page=1.*\&_page=1.*|_page=1.*\&_per_page=1).*>\; rel="first"# )
507
          ->header_like( 'Link', qr#(_per_page=1.*\&_page=4.*|_page=4.*\&_per_page=1).*>\; rel="last"# );
508
509
        t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 );
510
511
        $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->id . "/pickup_locations?" . "patron_id=" . $patron->id . "&_order_by=marc_org_code" . "&_per_page=1" )
512
          ->json_is( [$library_1_api] )
513
          ->header_is( 'X-Total-Count', '2' )
514
          ->header_is( 'X-Base-Total-Count', '2' )
515
          ->header_unlike( 'Link', qr|rel="prev"| )
516
          ->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1.*)>\; rel="next"# )
517
          ->header_like( 'Link', qr#(_per_page=1.*\&_page=1.*|_page=1.*\&_per_page=1).*>\; rel="first"# )
518
          ->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1).*>\; rel="last"# );
519
    };
520
479
    my $deleted_patron = $builder->build_object({ class => 'Koha::Patrons' });
521
    my $deleted_patron = $builder->build_object({ class => 'Koha::Patrons' });
480
    my $deleted_patron_id = $deleted_patron->id;
522
    my $deleted_patron_id = $deleted_patron->id;
481
    $deleted_patron->delete;
523
    $deleted_patron->delete;
482
- 

Return to bug 30133