2 use strict; use warnings;
3 use Test::More tests => 10;
4 use OpenILS::Utils::TestUtils;
5 use OpenILS::Utils::CStoreEditor qw/:funcs/;
6 use OpenILS::Application::Acq::Order;
8 use constant WORKSTATION_LIB => 4;
9 use constant WORKSTATION_NAME => 'BR1-test-30-age-protect-hold-capture';
11 diag("Tests hold capture with age protected items");
13 my $apputils = 'OpenILS::Application::AppUtils';
14 my $script = OpenILS::Utils::TestUtils->new();
19 my $workstation = $e->search_actor_workstation(
20 {name => WORKSTATION_NAME, owning_lib => WORKSTATION_LIB})->[0];
23 $script->authenticate({
25 password => 'demo123',
29 my $ws = $script->register_workstation(WORKSTATION_NAME, WORKSTATION_LIB);
33 $script->authenticate({
35 password => 'demo123',
37 workstation => WORKSTATION_NAME
40 my $ses = $script->session('open-ils.storage');
41 my $req = $ses->request('open-ils.storage.direct.actor.user.retrieve', 87);
42 if (my $resp = $req->recv) {
43 if (my $user = $resp->content) {
44 # -----------------------------------------------------------------------------
45 # 1. We'll use Smith, Sarah (with usrname 99999303411 and home lib SL1)
46 # -----------------------------------------------------------------------------
50 'User with id = 87 is 99999303411'
55 # -----------------------------------------------------------------------------
57 # -----------------------------------------------------------------------------
58 ok($script->authtoken, 'Have an authtoken');
62 $req = $script->session('open-ils.cat')->request(
63 'open-ils.cat.biblio.record.xml.create',
64 $script->authtoken, '<record xmlns="http://www.loc.gov/MARC21/slim"><leader>00620cam a2200205Ka 4500</leader><controlfield tag="005">20200515120426.0</controlfield><controlfield tag="008">070101s eng d</controlfield><datafield tag="245" ind1=" " ind2=" "><subfield code="a">test 30</subfield> </datafield></record>','TEST');
65 if (my $resp = $req->recv) {
66 if ($bre = $resp->content) {
67 # -----------------------------------------------------------------------------
68 # 3. Check for created bib
69 # -----------------------------------------------------------------------------
70 ok($bre->id > 0,'Created bib record');
71 diag('Bib ID = ' . $bre->id);
75 my $acn = Fieldmapper::asset::call_number->new;
78 $acn->record($bre->id);
79 $acn->creator(1); # admin
80 $acn->editor(1); # admin
81 $acn->owning_lib(5); # BR2 -- our test patron is at SL1, we want to set up age protection that'll kick in
82 $acn->label( 'test' );
83 $acn->create_date('now');
84 $acn->edit_date('now');
86 my $pcrud_ses = $script->session('open-ils.pcrud');
87 $pcrud_ses->connect();
88 my $xact = $pcrud_ses->request(
89 'open-ils.pcrud.transaction.begin',
92 my $acn_obj = $pcrud_ses->request(
93 'open-ils.pcrud.create.acn',
98 'open-ils.pcrud.transaction.commit',
101 $pcrud_ses->disconnect();
103 isa_ok(ref($acn_obj), 'Fieldmapper::asset::call_number', 'call number created');
105 my $acp = Fieldmapper::asset::copy->new;
108 $acp->call_number($acn_obj->id);
109 $acp->creator(1); # admin
110 $acp->editor(1); # admin
111 $acp->circ_lib(5); # BR2 -- our test patron is at SL1, we want to set up age protection that'll kick in
112 $acp->age_protect(1); # 3month
113 $acp->barcode( $bre->id . '-1' );
114 $acp->create_date('now');
115 $acp->edit_date('now');
116 $acp->active_date('now');
117 $acp->status_changed_time('now');
118 $acp->status(0); # available
119 $acp->location(1); # stacks
120 $acp->loan_duration(2); # normal
121 $acp->fine_level(2); # normal
123 $acp->deposit_amount(0.00);
126 $acp->opac_visible(1);
127 $acp->mint_condition(1);
128 $pcrud_ses = $script->session('open-ils.pcrud');
129 $pcrud_ses->connect();
130 $xact = $pcrud_ses->request(
131 'open-ils.pcrud.transaction.begin',
134 my $acp_obj = $pcrud_ses->request(
135 'open-ils.pcrud.create.acp',
140 'open-ils.pcrud.transaction.commit',
143 $pcrud_ses->disconnect();
145 isa_ok(ref($acp_obj), 'Fieldmapper::asset::copy', 'copy created');
147 diag('creating 200 holds... will take a moment');
150 my $start_time = [Time::HiRes::gettimeofday()];
151 foreach my $i (1..200) {
152 $hold = $apputils->simplereq(
154 'open-ils.circ.holds.test_and_create.batch.override',
158 patronid => 87, # our SL1 patron
159 pickup_lib => $i == 200 ? 5 : 8 # SL1 for every hold request but the last one, which is BR2
163 if (ref($hold->{result})) {
164 my $event = (ref($hold->{result}) eq 'ARRAY') ? $hold->{result}->[0] : $hold->{result};
165 if ($event->{textcode} eq 'HOLD_EXISTS') {
166 BAIL_OUT('.override did not work');
168 BAIL_OUT('Cannot place hold');
171 $hold = $apputils->simplereq(
173 'open-ils.pcrud.retrieve.ahr',
179 my $diff = Time::HiRes::tv_interval($start_time);
180 diag("took $diff seconds");
182 # Check that last hold exists.
183 isa_ok(ref($hold), 'Fieldmapper::action::hold_request', 'Got last hold') or BAIL_OUT('Need hold');
186 diag('attempting checkin');
188 $start_time = [Time::HiRes::gettimeofday()];
189 my $checkin_resp = $script->do_checkin({
190 barcode => $bre->id . '-1'});
191 $diff = Time::HiRes::tv_interval($start_time);
193 diag("took $diff seconds");
198 'Checkin request returned a HASH'
201 $checkin_resp->{ilsevent},
203 'Checkin returned a ROUTE ITEM event'
206 $checkin_resp->{payload}->{copy}->barcode,
208 'Checkin returned correct item in payload'
211 $checkin_resp->{payload}->{hold}->id,
213 'Checkin returned correct hold in payload'
216 #use Data::Dumper::Perltidy;
217 #diag( Dumper($checkin_resp) );