Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 5; |
20 |
use Test::More tests => 7; |
21 |
use Test::Mojo; |
21 |
use Test::Mojo; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
Lines 342-347
subtest 'delete() tests' => sub {
Link Here
|
342 |
}; |
342 |
}; |
343 |
}; |
343 |
}; |
344 |
|
344 |
|
|
|
345 |
subtest 'guarantors_can_see_charges() tests' => sub { |
346 |
|
347 |
plan tests => 11; |
348 |
|
349 |
t::lib::Mocks::mock_preference( 'RESTPublicAPI', 1 ); |
350 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
351 |
|
352 |
$schema->storage->txn_begin; |
353 |
|
354 |
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { privacy_guarantor_fines => 0 } }); |
355 |
my $password = 'thePassword123'; |
356 |
$patron->set_password({ password => $password, skip_validation => 1 }); |
357 |
my $userid = $patron->userid; |
358 |
my $patron_id = $patron->borrowernumber; |
359 |
|
360 |
t::lib::Mocks::mock_preference( 'AllowPatronToSetFinesVisibilityForGuarantor', 0 ); |
361 |
|
362 |
$t->put_ok( "//$userid:$password@/api/v1/public/patrons/$patron_id/guarantors/can_see_charges" => json => { allowed => Mojo::JSON->true } ) |
363 |
->status_is( 403 ) |
364 |
->json_is( '/error', 'The current configuration doesn\'t allow the requested action.' ); |
365 |
|
366 |
t::lib::Mocks::mock_preference( 'AllowPatronToSetFinesVisibilityForGuarantor', 1 ); |
367 |
|
368 |
$t->put_ok( "//$userid:$password@/api/v1/public/patrons/$patron_id/guarantors/can_see_charges" => json => { allowed => Mojo::JSON->true } ) |
369 |
->status_is( 200 ) |
370 |
->json_is( {} ); |
371 |
|
372 |
ok( $patron->discard_changes->privacy_guarantor_fines, 'privacy_guarantor_fines has been set correctly' ); |
373 |
|
374 |
$t->put_ok( "//$userid:$password@/api/v1/public/patrons/$patron_id/guarantors/can_see_charges" => json => { allowed => Mojo::JSON->false } ) |
375 |
->status_is( 200 ) |
376 |
->json_is( {} ); |
377 |
|
378 |
ok( !$patron->discard_changes->privacy_guarantor_fines, 'privacy_guarantor_fines has been set correctly' ); |
379 |
|
380 |
$schema->storage->txn_rollback; |
381 |
}; |
382 |
|
383 |
subtest 'guarantors_can_see_checkouts() tests' => sub { |
384 |
|
385 |
plan tests => 11; |
386 |
|
387 |
t::lib::Mocks::mock_preference( 'RESTPublicAPI', 1 ); |
388 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
389 |
|
390 |
$schema->storage->txn_begin; |
391 |
|
392 |
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { privacy_guarantor_checkouts => 0 } }); |
393 |
my $password = 'thePassword123'; |
394 |
$patron->set_password({ password => $password, skip_validation => 1 }); |
395 |
my $userid = $patron->userid; |
396 |
my $patron_id = $patron->borrowernumber; |
397 |
|
398 |
t::lib::Mocks::mock_preference( 'AllowPatronToSetCheckoutsVisibilityForGuarantor', 0 ); |
399 |
|
400 |
$t->put_ok( "//$userid:$password@/api/v1/public/patrons/$patron_id/guarantors/can_see_checkouts" => json => { allowed => Mojo::JSON->true } ) |
401 |
->status_is( 403 ) |
402 |
->json_is( '/error', 'The current configuration doesn\'t allow the requested action.' ); |
403 |
|
404 |
t::lib::Mocks::mock_preference( 'AllowPatronToSetCheckoutsVisibilityForGuarantor', 1 ); |
405 |
|
406 |
$t->put_ok( "//$userid:$password@/api/v1/public/patrons/$patron_id/guarantors/can_see_checkouts" => json => { allowed => Mojo::JSON->true } ) |
407 |
->status_is( 200 ) |
408 |
->json_is( {} ); |
409 |
|
410 |
ok( $patron->discard_changes->privacy_guarantor_checkouts, 'privacy_guarantor_checkouts has been set correctly' ); |
411 |
|
412 |
$t->put_ok( "//$userid:$password@/api/v1/public/patrons/$patron_id/guarantors/can_see_checkouts" => json => { allowed => Mojo::JSON->false } ) |
413 |
->status_is( 200 ) |
414 |
->json_is( {} ); |
415 |
|
416 |
ok( !$patron->discard_changes->privacy_guarantor_checkouts, 'privacy_guarantor_checkouts has been set correctly' ); |
417 |
|
418 |
$schema->storage->txn_rollback; |
419 |
}; |
420 |
|
345 |
# Centralized tests for 401s and 403s assuming the endpoint requires |
421 |
# Centralized tests for 401s and 403s assuming the endpoint requires |
346 |
# borrowers flag for access |
422 |
# borrowers flag for access |
347 |
sub unauthorized_access_tests { |
423 |
sub unauthorized_access_tests { |
348 |
- |
|
|