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 # Keep track of hold ids, so we can cancel them later.
26 # Login as admin at BR1.
27 my $authtoken = $script->authenticate({
37 # Register workstation.
38 my $ws = $script->find_or_register_workstation(BR1_WORKSTATION, BR1_ID);
41 'Found or registered workstation'
48 'Successfully logged out'
51 # Login as admin at BR1 using the workstation.
52 $authtoken = $script->authenticate({
56 workstation => BR1_WORKSTATION
63 # Check that OILS_SETTING_MAX_DUPLICATE_HOLDS is not set at BR1 and ancestors.
64 my $setting_value = $U->ou_ancestor_setting_value(BR1_ID, OILS_SETTING_MAX_DUPLICATE_HOLDS);
67 'circ.holds.max_duplicate_holds is not set for BR1'
70 # Check that OILS_SETTING_MAX_DUPLICATE_HOLDS is not set at BR2 and ancestors.
71 $setting_value = $U->ou_ancestor_setting_value(BR2_ID, OILS_SETTING_MAX_DUPLICATE_HOLDS);
74 'circ.holds.max_duplicate_holds is not set for BR2'
77 # Set OILS_SETTING_MAX_DUPLICATE_HOLDS to 5 at BR1.
78 $setting_value = $U->simplereq(
80 'open-ils.actor.org_unit.settings.update',
83 {OILS_SETTING_MAX_DUPLICATE_HOLDS, 5}
87 'circ.holds.max_duplicate_holds set to 5 for BR1'
91 my $patron1 = $U->simplereq(
93 'open-ils.actor.user.fleshed.retrieve_by_barcode',
99 'Fieldmapper::actor::user',
101 ) or BAIL_OUT('Need Patron1');
103 # Create a circ session for holds placement.
104 my $circ_session = $script->session('open-ils.circ');
106 # Place 5 holds for RECORD_ID for PATRON1. Expect success.
107 my $request = $circ_session->request(
108 'open-ils.circ.holds.test_and_create.batch',
112 patronid => $patron1->id(),
113 pickup_lib => $patron1->home_ou()
115 [RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID]
118 while (my $response = $request->recv()) {
119 my $result = $response->content();
120 if ($result->{result} && !ref $result->{result}) {
122 push(@holds, $result->{result});
129 'Placed 5 title holds for Patron 1'
132 # Place 1 hold for RECORD_ID for PATRON1. Expect HOLD_EXISTS.
133 $request = $circ_session->request(
134 'open-ils.circ.holds.test_and_create.batch',
138 patronid => $patron1->id(),
139 pickup_lib => $patron1->home_ou()
144 while (my $response = $request->recv()) {
145 my $result = $response->content();
146 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
147 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
148 $textcode = 'HOLD_EXISTS';
156 'Got HOLD_EXISTS placing 6th title hold for patron 1'
159 # Place 5 holds for METARECORD_ID for PATRON1. Expect success.
160 $request = $circ_session->request(
161 'open-ils.circ.holds.test_and_create.batch',
165 patronid => $patron1->id(),
166 pickup_lib => $patron1->home_ou()
168 [METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID]
171 while (my $response = $request->recv()) {
172 my $result = $response->content();
173 if ($result->{result} && !ref $result->{result}) {
175 push(@holds, $result->{result});
182 'Placed 5 metarecord holds for Patron 1'
185 # Place 1 hold for METARECORD_ID for PATRON1. Expect HOLD_EXISTS.
186 $request = $circ_session->request(
187 'open-ils.circ.holds.test_and_create.batch',
191 patronid => $patron1->id(),
192 pickup_lib => $patron1->home_ou()
197 while (my $response = $request->recv()) {
198 my $result = $response->content();
199 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
200 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
201 $textcode = 'HOLD_EXISTS';
209 'Got HOLD_EXISTS placing 6th metarecord hold for patron 1'
212 # Place 5 holds for COPY_ID for PATRON1. Expect 1 success and 4 HOLD_EXISTS.
213 $request = $circ_session->request(
214 'open-ils.circ.holds.test_and_create.batch',
218 patronid => $patron1->id(),
219 pickup_lib => $patron1->home_ou()
221 [COPY_ID, COPY_ID, COPY_ID, COPY_ID, COPY_ID]
224 $textcode = 0; # Using textcode as int this time.
225 while (my $response = $request->recv()) {
226 my $result = $response->content();
227 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
228 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
231 } elsif ($result->{result}) {
233 push(@holds, $result->{result});
240 'Placed 1 copy hold for patron 1'
245 'Got 4 HOLD_EXISTS on copy holds for patron 1'
249 my $patron2 = $U->simplereq(
251 'open-ils.actor.user.fleshed.retrieve_by_barcode',
257 'Fieldmapper::actor::user',
259 ) or BAIL_OUT('Need Patron 2');
261 # Place 5 holds for RECORD_ID for PATRON2. Expect 1 success and 4 HOLD_EXISTS.
262 $request = $circ_session->request(
263 'open-ils.circ.holds.test_and_create.batch',
267 patronid => $patron2->id(),
268 pickup_lib => $patron2->home_ou()
270 [RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID]
273 $textcode = 0; # Using textcode as int this time.
274 while (my $response = $request->recv()) {
275 my $result = $response->content();
276 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
277 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
280 } elsif ($result->{result}) {
282 push(@holds, $result->{result});
289 'Placed 1 title hold for patron 2'
294 'Got 4 HOLD_EXISTS on title holds for patron 2'
297 # Place 5 holds for METARECORD_ID for PATRON2. Expect 1 success and 4 HOLD_EXISTS.
298 $request = $circ_session->request(
299 'open-ils.circ.holds.test_and_create.batch',
303 patronid => $patron2->id(),
304 pickup_lib => $patron2->home_ou()
306 [METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID]
309 $textcode = 0; # Using textcode as int this time.
310 while (my $response = $request->recv()) {
311 my $result = $response->content();
312 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
313 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
316 } elsif ($result->{result}) {
318 push(@holds, $result->{result});
325 'Placed 1 metarecord hold for patron 2'
330 'Got 4 HOLD_EXISTS on metarecord holds for patron 2'
333 # Place 5 holds for COPY_ID for PATRON2. Expect 1 success and 4 HOLD_EXISTS.
334 $request = $circ_session->request(
335 'open-ils.circ.holds.test_and_create.batch',
339 patronid => $patron2->id(),
340 pickup_lib => $patron2->home_ou()
342 [COPY_ID, COPY_ID, COPY_ID, COPY_ID, COPY_ID]
345 $textcode = 0; # Using textcode as int this time.
346 while (my $response = $request->recv()) {
347 my $result = $response->content();
348 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
349 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
352 } elsif ($result->{result}) {
354 push(@holds, $result->{result});
361 'Placed 1 copy hold for patron 2'
366 'Got 4 HOLD_EXISTS on copy holds for patron 2'
369 # Cancel all of the holds placed.
370 # How many successes we expect.
371 my $expect = scalar(@holds);
373 foreach my $hold (@holds) {
374 my $result = $circ_session->request(
375 'open-ils.circ.hold.cancel',
379 'LP 1694058 perl test'
381 if ($result && ! ref $result) {
388 "Cancelled $expect holds"
394 # Test the permission by logging in as patron 1 and placing a title and metarecord hold.
397 my $patron_auth = $script->authenticate({
398 username => $patron1->usrname(),
399 password => 'leona1234',
404 'Logged in as patron 1'
407 # Place 5 holds for RECORD_ID as PATRON1. Expect 1 success and 4 HOLD_EXISTS.
408 $request = $circ_session->request(
409 'open-ils.circ.holds.test_and_create.batch',
413 patronid => $patron1->id(),
414 pickup_lib => $patron1->home_ou()
416 [RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID, RECORD_ID]
419 $textcode = 0; # Using textcode as int this time.
420 while (my $response = $request->recv()) {
421 my $result = $response->content();
422 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
423 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
426 } elsif ($result->{result}) {
428 push(@holds, $result->{result});
435 'Patron 1 placed 1 title hold'
440 'Patron 1 got 4 HOLD_EXISTS on title holds'
443 # Ditto for metarecord holds:
444 $request = $circ_session->request(
445 'open-ils.circ.holds.test_and_create.batch',
449 patronid => $patron1->id(),
450 pickup_lib => $patron1->home_ou()
452 [METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID, METARECORD_ID]
455 $textcode = 0; # Using textcode as int this time.
456 while (my $response = $request->recv()) {
457 my $result = $response->content();
458 if ($result->{result} && ref($result->{result}) eq 'ARRAY') {
459 if (grep {$_->{textcode} eq 'HOLD_EXISTS'} @{$result->{result}}) {
462 } elsif ($result->{result}) {
464 push(@holds, $result->{result});
471 'Patron 1 placed 1 metarecord hold'
476 'Patron 1 got 4 HOLD_EXISTS on metarecord holds'
479 # Cancel the patron-placed holds.
480 $expect = scalar(@holds);
482 foreach my $hold (@holds) {
483 my $result = $circ_session->request(
484 'open-ils.circ.hold.cancel',
488 'LP 1694058 perl test'
490 if ($result && ! ref $result) {
497 "Cancelled $expect patron holds"
503 # Unset OILS_SETTING_MAX_DUPLICATE_HOLDS at BR1.
504 $setting_value = $U->simplereq(
506 'open-ils.actor.org_unit.settings.update',
509 {OILS_SETTING_MAX_DUPLICATE_HOLDS, undef}
512 ! ref $setting_value,
513 'circ.holds.max_duplicate_holds unset for BR1'
516 # Logout. Because of a "bug" in Cronscript.pm, we need to log out in the order that we logged in.
517 $script->logout($authtoken);
518 $script->logout($patron_auth);
520 ! $script->authtoken,
521 'Successfully logged out'