2 use strict; use warnings;
3 use Test::More tests => 30;
4 use OpenILS::Utils::TestUtils;
5 use OpenILS::Const qw(:const);
7 diag("Test LP 1694058 multiple hold placement.");
9 my $script = OpenILS::Utils::TestUtils->new();
10 my $U = 'OpenILS::Application::AppUtils';
13 BR1_WORKSTATION => 'BR1-test-lp1694058-multiple-hold-placement.t',
16 PATRON1_BARCODE => '99999376864',
17 PATRON2_BARCODE => '99999342948',
23 # Because this may run multiple times, without a DB reload, we search
24 # for the workstation before registering it. Takes an authtoken, the
25 # id of the workstation lib, and the name of the workstation.
26 sub find_or_register_workstation {
27 my ($authtoken, $lib, $workstation) = @_;
29 my $r = $U->simplereq(
31 'open-ils.actor.workstation.list',
35 if ($r && $r->{$lib}) {
36 $ws = grep {$_->name() eq $workstation} @{$r->{$lib}};
39 $ws = $script->register_workstation($workstation, $lib);
45 # Keep track of hold ids, so we can cancel them later.
48 # Login as admin at BR1.
49 my $authtoken = $script->authenticate({
59 # Register workstation.
60 my $ws = find_or_register_workstation($authtoken, BR1_ID, BR1_WORKSTATION);
63 'Found or registered workstation'
70 'Successfully logged out'
73 # Login as admin at BR1 using the workstation.
74 $authtoken = $script->authenticate({
78 workstation => BR1_WORKSTATION
85 # Check that OILS_SETTING_MAX_DUPLICATE_HOLDS is not set at BR1 and ancestors.
86 my $setting_value = $U->ou_ancestor_setting_value(BR1_ID, OILS_SETTING_MAX_DUPLICATE_HOLDS);
89 'circ.holds.max_duplicate_holds is not set for BR1'
92 # Check that OILS_SETTING_MAX_DUPLICATE_HOLDS is not set at BR2 and ancestors.
93 $setting_value = $U->ou_ancestor_setting_value(BR2_ID, OILS_SETTING_MAX_DUPLICATE_HOLDS);
96 'circ.holds.max_duplicate_holds is not set for BR2'
99 # Set OILS_SETTING_MAX_DUPLICATE_HOLDS to 5 at BR1.
100 $setting_value = $U->simplereq(
102 'open-ils.actor.org_unit.settings.update',
105 {OILS_SETTING_MAX_DUPLICATE_HOLDS, 5}
108 ! ref $setting_value,
109 'circ.holds.max_duplicate_holds set to 5 for BR1'
113 my $patron1 = $U->simplereq(
115 'open-ils.actor.user.fleshed.retrieve_by_barcode',
121 'Fieldmapper::actor::user',
123 ) or BAIL_OUT('Need Patron1');
125 # Create a circ session for holds placement.
126 my $circ_session = $script->session('open-ils.circ');
128 # Place 5 holds for RECORD_ID for PATRON1. Expect success.
129 my $request = $circ_session->request(
130 'open-ils.circ.holds.test_and_create.batch',
134 patronid => $patron1->id(),
135 pickup_lib => $patron1->home_ou()
137 [RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID]
140 while (my $response = $request->recv()) {
141 my $result = $response->content();
142 if ($result->{result} && !ref $result->{result}) {
144 push(@holds, $result->{result});
151 'Placed 5 title holds for Patron 1'
154 # Place 1 hold for RECORD_ID for PATRON1. Expect HOLD_EXISTS.
155 $request = $circ_session->request(
156 'open-ils.circ.holds.test_and_create.batch',
160 patronid => $patron1->id(),
161 pickup_lib => $patron1->home_ou()
166 while (my $response = $request->recv()) {
167 my $result = $response->content();
168 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
169 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
170 $textcode = 'HOLD_EXISTS';
178 'Got HOLD_EXISTS placing 6th title hold for patron 1'
181 # Place 5 holds for METARECORD_ID for PATRON1. Expect success.
182 $request = $circ_session->request(
183 'open-ils.circ.holds.test_and_create.batch',
187 patronid => $patron1->id(),
188 pickup_lib => $patron1->home_ou()
190 [METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID]
193 while (my $response = $request->recv()) {
194 my $result = $response->content();
195 if ($result->{result} && !ref $result->{result}) {
197 push(@holds, $result->{result});
204 'Placed 5 metarecord holds for Patron 1'
207 # Place 1 hold for METARECORD_ID for PATRON1. Expect HOLD_EXISTS.
208 $request = $circ_session->request(
209 'open-ils.circ.holds.test_and_create.batch',
213 patronid => $patron1->id(),
214 pickup_lib => $patron1->home_ou()
219 while (my $response = $request->recv()) {
220 my $result = $response->content();
221 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
222 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
223 $textcode = 'HOLD_EXISTS';
231 'Got HOLD_EXISTS placing 6th metarecord hold for patron 1'
234 # Place 5 holds for COPY_ID for PATRON1. Expect 1 success and 4 HOLD_EXISTS.
235 $request = $circ_session->request(
236 'open-ils.circ.holds.test_and_create.batch',
240 patronid => $patron1->id(),
241 pickup_lib => $patron1->home_ou()
243 [COPY_ID, COPY_ID, COPY_ID, COPY_ID, COPY_ID]
246 $textcode = 0; # Using textcode as int this time.
247 while (my $response = $request->recv()) {
248 my $result = $response->content();
249 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
250 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
253 } elsif ($result->{result}) {
255 push(@holds, $result->{result});
262 'Placed 1 copy hold for patron 1'
267 'Got 4 HOLD_EXISTS on copy holds for patron 1'
271 my $patron2 = $U->simplereq(
273 'open-ils.actor.user.fleshed.retrieve_by_barcode',
279 'Fieldmapper::actor::user',
281 ) or BAIL_OUT('Need Patron 2');
283 # Place 5 holds for RECORD_ID for PATRON2. Expect 1 success and 4 HOLD_EXISTS.
284 $request = $circ_session->request(
285 'open-ils.circ.holds.test_and_create.batch',
289 patronid => $patron2->id(),
290 pickup_lib => $patron2->home_ou()
292 [RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID]
295 $textcode = 0; # Using textcode as int this time.
296 while (my $response = $request->recv()) {
297 my $result = $response->content();
298 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
299 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
302 } elsif ($result->{result}) {
304 push(@holds, $result->{result});
311 'Placed 1 title hold for patron 2'
316 'Got 4 HOLD_EXISTS on title holds for patron 2'
319 # Place 5 holds for METARECORD_ID for PATRON2. Expect 1 success and 4 HOLD_EXISTS.
320 $request = $circ_session->request(
321 'open-ils.circ.holds.test_and_create.batch',
325 patronid => $patron2->id(),
326 pickup_lib => $patron2->home_ou()
328 [METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID]
331 $textcode = 0; # Using textcode as int this time.
332 while (my $response = $request->recv()) {
333 my $result = $response->content();
334 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
335 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
338 } elsif ($result->{result}) {
340 push(@holds, $result->{result});
347 'Placed 1 metarecord hold for patron 2'
352 'Got 4 HOLD_EXISTS on metarecord holds for patron 2'
355 # Place 5 holds for COPY_ID for PATRON2. Expect 1 success and 4 HOLD_EXISTS.
356 $request = $circ_session->request(
357 'open-ils.circ.holds.test_and_create.batch',
361 patronid => $patron2->id(),
362 pickup_lib => $patron2->home_ou()
364 [COPY_ID, COPY_ID, COPY_ID, COPY_ID, COPY_ID]
367 $textcode = 0; # Using textcode as int this time.
368 while (my $response = $request->recv()) {
369 my $result = $response->content();
370 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
371 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
374 } elsif ($result->{result}) {
376 push(@holds, $result->{result});
383 'Placed 1 copy hold for patron 2'
388 'Got 4 HOLD_EXISTS on copy holds for patron 2'
391 # Cancel all of the holds placed.
392 # How many successes we expect.
393 my $expect = scalar(@holds);
395 foreach my $hold (@holds) {
396 my $result = $circ_session->request(
397 'open-ils.circ.hold.cancel',
401 'LP 1694058 perl test'
403 if ($result && ! ref $result) {
410 "Cancelled $expect holds"
416 # Test the permission by logging in as patron 1 and placing a title and metarecord hold.
419 my $patron_auth = $script->authenticate({
420 username => $patron1->usrname(),
421 password => 'leona1234',
426 'Logged in as patron 1'
429 # Place 5 holds for RECORD_ID as PATRON1. Expect 1 success and 4 HOLD_EXISTS.
430 $request = $circ_session->request(
431 'open-ils.circ.holds.test_and_create.batch',
435 patronid => $patron1->id(),
436 pickup_lib => $patron1->home_ou()
438 [RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID]
441 $textcode = 0; # Using textcode as int this time.
442 while (my $response = $request->recv()) {
443 my $result = $response->content();
444 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
445 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
448 } elsif ($result->{result}) {
450 push(@holds, $result->{result});
457 'Patron 1 placed 1 title hold'
462 'Patron 1 got 4 HOLD_EXISTS on title holds'
465 # Ditto for metarecord holds:
466 $request = $circ_session->request(
467 'open-ils.circ.holds.test_and_create.batch',
471 patronid => $patron1->id(),
472 pickup_lib => $patron1->home_ou()
474 [METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID]
477 $textcode = 0; # Using textcode as int this time.
478 while (my $response = $request->recv()) {
479 my $result = $response->content();
480 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
481 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
484 } elsif ($result->{result}) {
486 push(@holds, $result->{result});
493 'Patron 1 placed 1 metarecord hold'
498 'Patron 1 got 4 HOLD_EXISTS on metarecord holds'
501 # Cancel the patron-placed holds.
502 $expect = scalar(@holds);
504 foreach my $hold (@holds) {
505 my $result = $circ_session->request(
506 'open-ils.circ.hold.cancel',
510 'LP 1694058 perl test'
512 if ($result && ! ref $result) {
519 "Cancelled $expect patron holds"
525 # Unset OILS_SETTING_MAX_DUPLICATE_HOLDS at BR1.
526 $setting_value = $U->simplereq(
528 'open-ils.actor.org_unit.settings.update',
531 {OILS_SETTING_MAX_DUPLICATE_HOLDS, undef}
534 ! ref $setting_value,
535 'circ.holds.max_duplicate_holds unset for BR1'
538 # Logout. Because of a "bug" in Cronscript.pm, we need to log out in the order that we logged in.
539 $script->logout($authtoken);
540 $script->logout($patron_auth);
542 ! $script->authtoken,
543 'Successfully logged out'