Lines 18-24
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::NoWarnings; |
20 |
use Test::NoWarnings; |
21 |
use Test::More tests => 4; |
21 |
use Test::More tests => 5; |
22 |
|
22 |
|
23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
24 |
use Test::MockObject; |
24 |
use Test::MockObject; |
Lines 264-272
subtest 'list() tests' => sub {
Link Here
|
264 |
$schema->storage->txn_rollback; |
264 |
$schema->storage->txn_rollback; |
265 |
}; |
265 |
}; |
266 |
|
266 |
|
267 |
subtest 'patron_list() tests' => sub { |
267 |
subtest 'public_patron_list() tests' => sub { |
|
|
268 |
|
269 |
plan tests => 13; |
268 |
|
270 |
|
269 |
plan tests => 15; |
271 |
$schema->storage->txn_begin; |
270 |
|
272 |
|
271 |
# Mock ILLBackend (as object) |
273 |
# Mock ILLBackend (as object) |
272 |
my $backend = Test::MockObject->new; |
274 |
my $backend = Test::MockObject->new; |
Lines 283-318
subtest 'patron_list() tests' => sub {
Link Here
|
283 |
sub { my $self = shift; $self->{_my_backend} = $backend; return $self } |
285 |
sub { my $self = shift; $self->{_my_backend} = $backend; return $self } |
284 |
); |
286 |
); |
285 |
|
287 |
|
286 |
$schema->storage->txn_begin; |
288 |
my $password = 'thePassword123'; |
287 |
|
|
|
288 |
Koha::ILL::Requests->search->delete; |
289 |
|
289 |
|
290 |
my $requester = $builder->build_object( |
290 |
my $patron_1 = $builder->build_object( |
291 |
{ |
291 |
{ |
292 |
class => 'Koha::Patrons', |
292 |
class => 'Koha::Patrons', |
293 |
value => { flags => 0 } |
293 |
value => { flags => 0 } |
294 |
} |
294 |
} |
295 |
); |
295 |
); |
296 |
my $password = 'thePassword123'; |
296 |
my $patron_1_userid = $patron_1->userid; |
297 |
$requester->set_password( { password => $password, skip_validation => 1 } ); |
297 |
my $patron_1_id = $patron_1->id; |
298 |
my $requester_userid = $requester->userid; |
298 |
|
299 |
my $requester_number = $requester->borrowernumber; |
299 |
$patron_1->set_password( { password => $password, skip_validation => 1 } ); |
300 |
|
300 |
|
301 |
my $observer = $builder->build_object( |
301 |
my $patron_2 = $builder->build_object( |
302 |
{ |
302 |
{ |
303 |
class => 'Koha::Patrons', |
303 |
class => 'Koha::Patrons', |
304 |
value => { flags => 0 } |
304 |
value => { flags => 0 } |
305 |
} |
305 |
} |
306 |
); |
306 |
); |
307 |
|
307 |
|
308 |
$observer->set_password( { password => $password, skip_validation => 1 } ); |
308 |
$patron_2->set_password( { password => $password, skip_validation => 1 } ); |
309 |
my $observer_userid = $observer->userid; |
309 |
|
310 |
my $observer_number = $observer->borrowernumber; |
310 |
my $patron_2_userid = $patron_2->userid; |
|
|
311 |
my $patron_2_id = $patron_2->id; |
311 |
|
312 |
|
312 |
# No requests yet, expect empty for both |
313 |
# No requests yet, expect empty for both |
313 |
$t->get_ok("//$requester_userid:$password@/api/v1/patrons/$requester_number/ill/requests")->status_is(200) |
314 |
$t->get_ok("//$patron_1_userid:$password@/api/v1/public/patrons/$patron_1_id/ill/requests")->status_is(200) |
314 |
->json_is( [] ); |
315 |
->json_is( [] ); |
315 |
$t->get_ok("//$observer_userid:$password@/api/v1/patrons/$observer_number/ill/requests")->status_is(200) |
316 |
|
|
|
317 |
$t->get_ok("//$patron_2_userid:$password@/api/v1/public/patrons/$patron_2_id/ill/requests")->status_is(200) |
316 |
->json_is( [] ); |
318 |
->json_is( [] ); |
317 |
|
319 |
|
318 |
for ( 0 .. 25 ) { |
320 |
for ( 0 .. 25 ) { |
Lines 320-326
subtest 'patron_list() tests' => sub {
Link Here
|
320 |
{ |
322 |
{ |
321 |
class => 'Koha::ILL::Requests', |
323 |
class => 'Koha::ILL::Requests', |
322 |
value => { |
324 |
value => { |
323 |
borrowernumber => $requester_number, |
325 |
borrowernumber => $patron_1_id, |
324 |
batch_id => undef, |
326 |
batch_id => undef, |
325 |
status => 'NEW', |
327 |
status => 'NEW', |
326 |
backend => $backend->name, |
328 |
backend => $backend->name, |
Lines 331-350
subtest 'patron_list() tests' => sub {
Link Here
|
331 |
} |
333 |
} |
332 |
|
334 |
|
333 |
# Other user should not see anything |
335 |
# Other user should not see anything |
334 |
$t->get_ok("//$observer_userid:$password@/api/v1/patrons/$observer_number/ill/requests")->status_is(200) |
336 |
$t->get_ok("//$patron_2_userid:$password@/api/v1/public/patrons/$patron_2_id/ill/requests")->status_is(200) |
335 |
->json_is( [] ); |
337 |
->json_is( [] ); |
336 |
|
338 |
|
337 |
# Staff notes hidden in the public API |
339 |
# Staff notes hidden in the public API |
338 |
$t->get_ok("//$requester_userid:$password@/api/v1/patrons/$requester_number/ill/requests")->status_is(200) |
340 |
$t->get_ok("//$patron_1_userid:$password@/api/v1/public/patrons/$patron_1_id/ill/requests?_per_page=-1") |
339 |
->json_is( |
341 |
->status_is(200)->json_is( |
340 |
'/0/staff_notes' => undef, |
342 |
'/0/staff_notes' => undef, |
341 |
); |
343 |
); |
342 |
|
344 |
|
343 |
# Not all requests get returned, pagination works |
345 |
my $reqs = $t->tx->res->json; |
344 |
$t->get_ok("//$requester_userid:$password@/api/v1/patrons/$requester_number/ill/requests")->status_is(200) |
346 |
is( scalar @{$reqs}, 26, 'All ILL requests returned for the patron' ); |
345 |
->json_is( |
347 |
|
346 |
'/21' => undef, |
348 |
$schema->storage->txn_rollback; |
|
|
349 |
}; |
350 |
|
351 |
subtest 'patron_list() tests' => sub { |
352 |
|
353 |
plan tests => 7; |
354 |
|
355 |
$schema->storage->txn_begin; |
356 |
|
357 |
# Mock ILLBackend (as object) |
358 |
my $backend = Test::MockObject->new; |
359 |
$backend->set_isa('Koha::Illbackends::Mock'); |
360 |
$backend->set_always( 'name', 'Mock' ); |
361 |
$backend->mock( |
362 |
'status_graph', sub { }, |
363 |
); |
364 |
|
365 |
# Mock Koha::ILL::Request::load_backend (to load Mocked Backend) |
366 |
my $illreqmodule = Test::MockModule->new('Koha::ILL::Request'); |
367 |
$illreqmodule->mock( |
368 |
'load_backend', |
369 |
sub { my $self = shift; $self->{_my_backend} = $backend; return $self } |
370 |
); |
371 |
|
372 |
my $password = 'thePassword123'; |
373 |
|
374 |
my $patron = $builder->build_object( |
375 |
{ |
376 |
class => 'Koha::Patrons', |
377 |
value => { flags => 2**22 } # 22 => ill |
378 |
} |
379 |
); |
380 |
|
381 |
my $user_id = $patron->userid; |
382 |
my $patron_id = $patron->id; |
383 |
|
384 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
385 |
|
386 |
# No requests yet, expect empty for both |
387 |
$t->get_ok("//$user_id:$password@/api/v1/patrons/$patron_id/ill/requests")->status_is(200)->json_is( [] ); |
388 |
|
389 |
my $secret_notes = 'secret staff notes'; |
390 |
|
391 |
for ( 0 .. 25 ) { |
392 |
$builder->build_object( |
393 |
{ |
394 |
class => 'Koha::ILL::Requests', |
395 |
value => { |
396 |
borrowernumber => $patron_id, |
397 |
batch_id => undef, |
398 |
status => 'NEW', |
399 |
backend => $backend->name, |
400 |
notesstaff => $secret_notes, |
401 |
} |
402 |
} |
347 |
); |
403 |
); |
|
|
404 |
} |
405 |
|
406 |
# Staff notes available in the staff endpoint |
407 |
$t->get_ok("//$user_id:$password@/api/v1/patrons/$patron_id/ill/requests?_per_page=-1")->status_is(200)->json_is( |
408 |
'/0/staff_notes' => $secret_notes, |
409 |
); |
410 |
|
411 |
my $reqs = $t->tx->res->json; |
412 |
is( scalar @{$reqs}, 26, 'All ILL requests returned for the patron' ); |
348 |
|
413 |
|
349 |
$schema->storage->txn_rollback; |
414 |
$schema->storage->txn_rollback; |
350 |
}; |
415 |
}; |
351 |
- |
|
|