]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/live_t/30-lp1508208-age-protect-hold-capture.t
LP#1508208: live_t/ test for this branch
[Evergreen.git] / Open-ILS / src / perlmods / live_t / 30-lp1508208-age-protect-hold-capture.t
1 #!perl
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;
7
8 use constant WORKSTATION_LIB => 4;
9 use constant WORKSTATION_NAME => 'BR1-test-30-age-protect-hold-capture';
10
11 diag("Tests hold capture with age protected items");
12
13 my $apputils = 'OpenILS::Application::AppUtils';
14 my $script = OpenILS::Utils::TestUtils->new();
15 $script->bootstrap;
16 my $e = new_editor();
17 $e->init;
18
19 my $workstation = $e->search_actor_workstation(
20     {name => WORKSTATION_NAME, owning_lib => WORKSTATION_LIB})->[0];
21
22 if (!$workstation) {
23     $script->authenticate({
24         username => 'admin',
25         password => 'demo123',
26         type => 'staff'
27     });
28
29     my $ws = $script->register_workstation(WORKSTATION_NAME, WORKSTATION_LIB);
30     $script->logout();
31 }
32
33 $script->authenticate({
34     username => 'admin',
35     password => 'demo123',
36     type => 'staff',
37     workstation => WORKSTATION_NAME
38 });
39
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 # -----------------------------------------------------------------------------
47         is(
48             $user->usrname,
49             '99999303411',
50             'User with id = 87 is 99999303411'
51         );
52     }
53 }
54
55 # -----------------------------------------------------------------------------
56 # 2. Check for auth
57 # -----------------------------------------------------------------------------
58 ok($script->authtoken, 'Have an authtoken');
59
60
61 my $bre;
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);
72     }
73 }
74
75 my $acn = Fieldmapper::asset::call_number->new;
76 $acn->isnew(1);
77 $acn->deleted(0);
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');
85
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',
90     $script->authtoken
91 )->gather(1);
92 my $acn_obj = $pcrud_ses->request(
93     'open-ils.pcrud.create.acn',
94     $script->authtoken,
95     $acn
96 )->gather(1);
97 $pcrud_ses->request(
98     'open-ils.pcrud.transaction.commit',
99     $script->authtoken
100 )->gather(1);
101 $pcrud_ses->disconnect();
102 undef($pcrud_ses);
103 isa_ok(ref($acn_obj), 'Fieldmapper::asset::call_number', 'call number created');
104
105 my $acp = Fieldmapper::asset::copy->new;
106 $acp->isnew(1);
107 $acp->deleted(0);
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
122 $acp->deposit(0);
123 $acp->deposit_amount(0.00);
124 $acp->ref(0);
125 $acp->holdable(1);
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',
132     $script->authtoken
133 )->gather(1);
134 my $acp_obj = $pcrud_ses->request(
135     'open-ils.pcrud.create.acp',
136     $script->authtoken,
137     $acp
138 )->gather(1);
139 $pcrud_ses->request(
140     'open-ils.pcrud.transaction.commit',
141     $script->authtoken
142 )->gather(1);
143 $pcrud_ses->disconnect();
144 undef($pcrud_ses);
145 isa_ok(ref($acp_obj), 'Fieldmapper::asset::copy', 'copy created');
146
147 diag('creating 200 holds... will take a moment');
148
149 my $hold;
150 my $start_time = [Time::HiRes::gettimeofday()];
151 foreach my $i (1..200) {
152     $hold = $apputils->simplereq(
153         'open-ils.circ',
154         'open-ils.circ.holds.test_and_create.batch.override',
155         $script->authtoken,
156         {   
157             hold_type => 'T',
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
160         },
161         [$bre->id]
162     );
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');
167         } else {
168             BAIL_OUT('Cannot place hold');
169         }
170     } else {
171         $hold = $apputils->simplereq(
172             'open-ils.pcrud',
173             'open-ils.pcrud.retrieve.ahr',
174             $script->authtoken,
175             $hold->{result}
176         );  
177     }
178 }
179 my $diff = Time::HiRes::tv_interval($start_time);
180 diag("took $diff seconds");
181
182 # Check that last hold exists.
183 isa_ok(ref($hold), 'Fieldmapper::action::hold_request', 'Got last hold') or BAIL_OUT('Need hold');
184
185
186 diag('attempting checkin');
187
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);
192
193 diag("took $diff seconds");
194
195 is(
196     ref $checkin_resp,
197     'HASH',
198     'Checkin request returned a HASH'
199 );
200 is(
201     $checkin_resp->{ilsevent},
202     7000,
203     'Checkin returned a ROUTE ITEM event'
204 );
205 is(
206     $checkin_resp->{payload}->{copy}->barcode,
207     $bre->id . '-1',
208     'Checkin returned correct item in payload'
209 );
210 is(
211     $checkin_resp->{payload}->{hold}->id,
212     $hold->id,
213     'Checkin returned correct hold in payload'
214 );
215
216 #use Data::Dumper::Perltidy;
217 #diag( Dumper($checkin_resp) );
218
219