|
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 => 3; |
21 |
use Test::More tests => 4; |
| 22 |
|
22 |
|
| 23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
| 24 |
use Test::MockObject; |
24 |
use Test::MockObject; |
|
Lines 264-269
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 { |
| 268 |
|
| 269 |
plan tests => 15; |
| 270 |
|
| 271 |
# Mock ILLBackend (as object) |
| 272 |
my $backend = Test::MockObject->new; |
| 273 |
$backend->set_isa('Koha::Illbackends::Mock'); |
| 274 |
$backend->set_always( 'name', 'Mock' ); |
| 275 |
$backend->mock( |
| 276 |
'status_graph', sub { }, |
| 277 |
); |
| 278 |
|
| 279 |
# Mock Koha::ILL::Request::load_backend (to load Mocked Backend) |
| 280 |
my $illreqmodule = Test::MockModule->new('Koha::ILL::Request'); |
| 281 |
$illreqmodule->mock( |
| 282 |
'load_backend', |
| 283 |
sub { my $self = shift; $self->{_my_backend} = $backend; return $self } |
| 284 |
); |
| 285 |
|
| 286 |
$schema->storage->txn_begin; |
| 287 |
|
| 288 |
Koha::ILL::Requests->search->delete; |
| 289 |
|
| 290 |
my $requester = $builder->build_object( |
| 291 |
{ |
| 292 |
class => 'Koha::Patrons', |
| 293 |
value => { flags => 0 } |
| 294 |
} |
| 295 |
); |
| 296 |
my $password = 'thePassword123'; |
| 297 |
$requester->set_password( { password => $password, skip_validation => 1 } ); |
| 298 |
my $requester_userid = $requester->userid; |
| 299 |
my $requester_number = $requester->borrowernumber; |
| 300 |
|
| 301 |
my $observer = $builder->build_object( |
| 302 |
{ |
| 303 |
class => 'Koha::Patrons', |
| 304 |
value => { flags => 0 } |
| 305 |
} |
| 306 |
); |
| 307 |
|
| 308 |
$observer->set_password( { password => $password, skip_validation => 1 } ); |
| 309 |
my $observer_userid = $observer->userid; |
| 310 |
my $observer_number = $observer->borrowernumber; |
| 311 |
|
| 312 |
# No requests yet, expect empty for both |
| 313 |
$t->get_ok("//$requester_userid:$password@/api/v1/patrons/$requester_number/ill/requests")->status_is(200)->json_is( [] ); |
| 314 |
$t->get_ok("//$observer_userid:$password@/api/v1/patrons/$observer_number/ill/requests")->status_is(200)->json_is( [] ); |
| 315 |
|
| 316 |
for (0..25) { |
| 317 |
$builder->build_object( |
| 318 |
{ |
| 319 |
class => 'Koha::ILL::Requests', |
| 320 |
value => { |
| 321 |
borrowernumber => $requester_number, |
| 322 |
batch_id => undef, |
| 323 |
status => 'NEW', |
| 324 |
backend => $backend->name, |
| 325 |
notesstaff => 'secret staff notes' |
| 326 |
} |
| 327 |
} |
| 328 |
); |
| 329 |
} |
| 330 |
|
| 331 |
# Other user should not see anything |
| 332 |
$t->get_ok("//$observer_userid:$password@/api/v1/patrons/$observer_number/ill/requests")->status_is(200)->json_is( [] ); |
| 333 |
|
| 334 |
# Staff notes hidden in the public API |
| 335 |
$t->get_ok("//$requester_userid:$password@/api/v1/patrons/$requester_number/ill/requests")->status_is(200)->json_is( |
| 336 |
'/0/staff_notes' => undef, |
| 337 |
); |
| 338 |
|
| 339 |
# Not all requests get returned, pagination works |
| 340 |
$t->get_ok("//$requester_userid:$password@/api/v1/patrons/$requester_number/ill/requests")->status_is(200)->json_is( |
| 341 |
'/21' => undef, |
| 342 |
); |
| 343 |
|
| 344 |
$schema->storage->txn_rollback; |
| 345 |
}; |
| 346 |
|
| 267 |
subtest 'add() tests' => sub { |
347 |
subtest 'add() tests' => sub { |
| 268 |
|
348 |
|
| 269 |
plan tests => 2; |
349 |
plan tests => 2; |
| 270 |
- |
|
|