]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/live_t/19-lp1306666-abort-transit-copy-status.t
LP1615805 No inputs after submit in patron search (AngularJS)
[Evergreen.git] / Open-ILS / src / perlmods / live_t / 19-lp1306666-abort-transit-copy-status.t
1 #!perl
2 use strict; use warnings;
3 use Test::More tests => 26;
4 use OpenILS::Utils::TestUtils;
5 use OpenILS::Const qw(:const);
6
7 diag("Test LP 1306666 abort transit copy status fix.");
8
9 my $script = OpenILS::Utils::TestUtils->new();
10 my $apputils = 'OpenILS::Application::AppUtils';
11
12 use constant {
13     BR1_WORKSTATION => 'BR1-test-lp1306666-abort-transit-copyt-status.t',
14     BR1_ID => 4,
15     BR3_WORKSTATION => 'BR3-test-lp1306666-abort-transit-copyt-status.t',
16     BR3_ID => 6,
17     PBARCODE => '99999378730',
18     CBARCODE => 'CONC4000036'
19 };
20
21 # Store authtokens
22 my @authtoken = ();
23
24 # Login as staff at BR1
25 $authtoken[0] = $script->authenticate({
26     username => 'br1vcampbell',
27     password => 'vincentc1234',
28     type => 'staff'
29 });
30
31 # Register workstation at BR1.
32 unless ($script->find_workstation(BR1_WORKSTATION, BR1_ID)) {
33     $script->register_workstation(BR1_WORKSTATION, BR1_ID);
34 }
35
36 # Logout of BR1.
37 $script->logout($authtoken[0]);
38
39 # Login as staff at BR1 using workstation.
40 $authtoken[0] = $script->authenticate({
41     username => 'br1vcampbell',
42     password => 'vincentc1234',
43     type => 'staff',
44     workstation => BR1_WORKSTATION
45 });
46
47 # Login as staff at BR3
48 $authtoken[1] = $script->authenticate({
49     username => 'br3sforbes',
50     password => 'samuelf1234',
51     type => 'staff'
52 });
53
54 # Register workstation at BR3.
55 unless ($script->find_workstation(BR3_WORKSTATION, BR3_ID)) {
56     $script->register_workstation(BR3_WORKSTATION, BR3_ID);
57 }
58
59 # Logout of BR3.
60 $script->logout($authtoken[1]);
61
62 # Login as staff at BR3 using workstation.
63 $authtoken[1] = $script->authenticate({
64     username => 'br3sforbes',
65     password => 'samuelf1234',
66     type => 'staff',
67     workstation => BR3_WORKSTATION
68 });
69
70 # Retrieve copy at BR1
71 my $copy = $apputils->simplereq(
72     'open-ils.search',
73     'open-ils.search.asset.copy.find_by_barcode',
74     CBARCODE
75 );
76
77 # Check that copy exists.
78 isa_ok(ref($copy), 'Fieldmapper::asset::copy', 'Got copy') or BAIL_OUT('Need copy');
79
80 # Retrieve patron at BR3
81 my $patron = $apputils->simplereq(
82     'open-ils.actor',
83     'open-ils.actor.user.fleshed.retrieve_by_barcode',
84     $authtoken[1],
85     PBARCODE
86 );
87
88 # Check that patron exists.
89 isa_ok(ref($patron), 'Fieldmapper::actor::user', 'Got patron') or BAIL_OUT('Need patron');
90
91 # Place copy hold for patron pickup at BR3.
92 my $hold = $apputils->simplereq(
93     'open-ils.circ',
94     'open-ils.circ.holds.test_and_create.batch',
95     $authtoken[1],
96     {
97         hold_type => 'C',
98         patronid => $patron->id(),
99         pickup_lib => BR3_ID
100     },
101     [$copy->id()]
102 );
103 if (ref($hold->{result})) {
104     my $event = (ref($hold->{result}) eq 'ARRAY') ? $hold->{result}->[0] : $hold->{result};
105     if ($event->{textcode} eq 'HOLD_EXISTS') {
106         my $target = $hold->{target};
107         $hold = $apputils->simplereq(
108             'open-ils.pcrud',
109             'open-ils.pcrud.search.ahr',
110             $authtoken[1],
111             {target => $target, usr => $patron->id(), fulfillment_time => undef, cancel_time => undef}
112         );
113     } else {
114         BAIL_OUT('Cannot place hold');
115     }
116 } else {
117     $hold = $apputils->simplereq(
118         'open-ils.pcrud',
119         'open-ils.pcrud.retrieve.ahr',
120         $authtoken[1],
121         $hold->{result}
122     );
123 }
124
125 # Check that hold exists.
126 isa_ok(ref($hold), 'Fieldmapper::action::hold_request', 'Got hold') or BAIL_OUT('Need hold');
127
128 # Check copy in at BR1
129 my $checkin = $apputils->simplereq(
130     'open-ils.circ',
131     'open-ils.circ.checkin',
132     $authtoken[0],
133     {barcode => CBARCODE}
134 );
135 subtest 'Got ROUTE_ITEM event 1' => sub {
136     plan tests => 3;
137     is(ref($checkin), 'HASH', 'Got event');
138     is($checkin->{textcode}, 'ROUTE_ITEM', 'Route item event');
139     is($checkin->{org}, BR3_ID, 'ROUTE_ITEM event destination');
140 };
141
142 # Check copy transit.
143 my $transit = $apputils->simplereq(
144     'open-ils.pcrud',
145     'open-ils.pcrud.search.ahtc',
146     $authtoken[0],
147     {target_copy => $copy->id(), hold => $hold->id(), dest_recv_time => undef}
148 );
149 subtest 'Got hold transit 1' => sub {
150     plan tests => 4;
151     isa_ok(ref($transit), 'Fieldmapper::action::hold_transit_copy', 'Got hold transit copy');
152     is($transit->dest(), BR3_ID, 'Transit destination');
153     is($transit->source(), BR1_ID, 'Transit source');
154     is($transit->copy_status(), OILS_COPY_STATUS_ON_HOLDS_SHELF, 'Transit copy status');
155 };
156
157 # Check copy status.
158 $copy = $apputils->simplereq(
159     'open-ils.pcrud',
160     'open-ils.pcrud.retrieve.acp',
161     $authtoken[0],
162     $copy->id()
163 );
164 is($copy->status(), OILS_COPY_STATUS_IN_TRANSIT, 'Copy in transit');
165
166 # Abort the transit.
167 my $abort = $apputils->simplereq(
168     'open-ils.circ',
169     'open-ils.circ.transit.abort',
170     $authtoken[0],
171     {transitid => $transit->id()}
172 );
173 is($abort, 1, 'Transit aborted');
174
175 # Check copy status.
176 $copy = $apputils->simplereq(
177     'open-ils.pcrud',
178     'open-ils.pcrud.retrieve.acp',
179     $authtoken[0],
180     $copy->id()
181 );
182 is($copy->status(), OILS_COPY_STATUS_CANCELED_TRANSIT, 'Copy in Canceled Transit status');
183
184 # Check copy in at BR1
185 $checkin = $apputils->simplereq(
186     'open-ils.circ',
187     'open-ils.circ.checkin',
188     $authtoken[0],
189     {barcode => CBARCODE}
190 );
191 subtest 'Got ROUTE_ITEM event 2' => sub {
192     plan tests => 3;
193     is(ref($checkin), 'HASH', 'Got event');
194     is($checkin->{textcode}, 'ROUTE_ITEM', 'Route item event');
195     is($checkin->{org}, BR3_ID, 'ROUTE_ITEM event destination');
196 };
197
198 # Check copy transit.
199 $transit = $apputils->simplereq(
200     'open-ils.pcrud',
201     'open-ils.pcrud.search.ahtc',
202     $authtoken[0],
203     {target_copy => $copy->id(), hold => $hold->id(), dest_recv_time => undef}
204 );
205 subtest 'Got hold transit 2' => sub {
206     plan tests => 4;
207     isa_ok(ref($transit), 'Fieldmapper::action::hold_transit_copy', 'Got hold transit copy');
208     is($transit->dest(), BR3_ID, 'Transit destination');
209     is($transit->source(), BR1_ID, 'Transit source');
210     is($transit->copy_status(), OILS_COPY_STATUS_ON_HOLDS_SHELF, 'Transit copy status');
211 };
212
213 # Check copy status.
214 $copy = $apputils->simplereq(
215     'open-ils.pcrud',
216     'open-ils.pcrud.retrieve.acp',
217     $authtoken[0],
218     $copy->id()
219 );
220 is($copy->status(), OILS_COPY_STATUS_IN_TRANSIT, 'Copy in transit 2');
221
222 # Check copy in at BR3.
223 $checkin = $apputils->simplereq(
224     'open-ils.circ',
225     'open-ils.circ.checkin',
226     $authtoken[1],
227     {barcode => CBARCODE}
228 );
229 subtest 'Checkin at destination' => sub{
230     plan tests => 3;
231     is(ref($checkin), 'HASH', 'Got event');
232     is($checkin->{textcode}, 'SUCCESS', 'Event was successful');
233     is($checkin->{ishold}, 1, 'Check In filled hold');
234 };
235
236 # Check hold is on shelf.
237 $hold = $apputils->simplereq(
238     'open-ils.pcrud',
239     'open-ils.pcrud.retrieve.ahr',
240     $authtoken[1],
241     $hold->id()
242 );
243 ok(defined($hold->shelf_time()), 'Hold has shelf time');
244
245 # Check copy status.
246 $copy = $apputils->simplereq(
247     'open-ils.pcrud',
248     'open-ils.pcrud.retrieve.acp',
249     $authtoken[1],
250     $copy->id()
251 );
252 is($copy->status(), OILS_COPY_STATUS_ON_HOLDS_SHELF, 'Copy on holds shelf');
253
254 # Check copy out to patron at BR3.
255 my $checkout = $apputils->simplereq(
256     'open-ils.circ',
257     'open-ils.circ.checkout.full',
258     $authtoken[1],
259     {copy_id => $copy->id(), patron_id => $patron->id()}
260 );
261 subtest 'Checkout to patron' => sub {
262     plan tests => 2;
263     is(ref($checkout), 'HASH', 'Got checkout event');
264     is($checkout->{textcode}, 'SUCCESS', 'Checkout succeeded');
265 };
266
267 # Check the hold is fulfilled.
268 $hold = $apputils->simplereq(
269     'open-ils.pcrud',
270     'open-ils.pcrud.retrieve.ahr',
271     $authtoken[1],
272     $hold->id()
273 );
274 ok(defined($hold->fulfillment_time()), 'Hold was fulfilled');
275
276 # Check copy status.
277 $copy = $apputils->simplereq(
278     'open-ils.pcrud',
279     'open-ils.pcrud.retrieve.acp',
280     $authtoken[1],
281     $copy->id()
282 );
283 is($copy->status(), OILS_COPY_STATUS_CHECKED_OUT, 'Copy is checked out');
284
285 # Make a transit from BR3 to BR1 for the copy.
286 # We make the transit with pcrud, because
287 # open-ils.circ.copy_transit.create changes the copy status.
288 my $new_transit = Fieldmapper::action::transit_copy->new();
289 $new_transit->source(BR3_ID);
290 $new_transit->dest(BR1_ID);
291 $new_transit->target_copy($copy->id());
292 $new_transit->copy_status(OILS_COPY_STATUS_RESHELVING);
293 $new_transit->source_send_time('now');
294 my $pcrud_ses = $script->session('open-ils.pcrud');
295 $pcrud_ses->connect();
296 my $xact = $pcrud_ses->request(
297     'open-ils.pcrud.transaction.begin',
298     $authtoken[1]
299 )->gather(1);
300 $transit = $pcrud_ses->request(
301     'open-ils.pcrud.create.atc',
302     $authtoken[1],
303     $new_transit
304 )->gather(1);
305 $pcrud_ses->request(
306     'open-ils.pcrud.transaction.commit',
307     $authtoken[1]
308 )->gather(1);
309 $pcrud_ses->disconnect();
310 undef($pcrud_ses);
311 isa_ok(ref($transit), 'Fieldmapper::action::transit_copy', 'Transit created');
312
313 # Check the transit.
314 $transit = $apputils->simplereq(
315     'open-ils.pcrud',
316     'open-ils.pcrud.search.atc',
317     $authtoken[1],
318     {target_copy => $copy->id(), source => BR3_ID, dest => BR1_ID, dest_recv_time => undef}
319 );
320 subtest 'Got transit 1' => sub {
321     plan tests => 4;
322     isa_ok(ref($transit), 'Fieldmapper::action::transit_copy', 'Got transit copy');
323     is($transit->dest(), BR1_ID, 'Transit destination');
324     is($transit->source(), BR3_ID, 'Transit source');
325     is($transit->copy_status(), OILS_COPY_STATUS_RESHELVING, 'Transit copy status');
326 };
327
328 # Abort the transit.
329 $abort = $apputils->simplereq(
330     'open-ils.circ',
331     'open-ils.circ.transit.abort',
332     $authtoken[1],
333     {transitid => $transit->id()}
334 );
335 is($abort, 1, 'Transit 1 aborted');
336
337 # Check copy status.
338 $copy = $apputils->simplereq(
339     'open-ils.pcrud',
340     'open-ils.pcrud.retrieve.acp',
341     $authtoken[1],
342     $copy->id()
343 );
344 is($copy->status(), OILS_COPY_STATUS_CHECKED_OUT, 'Copy is checked out after transit abort');
345
346 # Check copy in at BR3.
347 $checkin = $apputils->simplereq(
348     'open-ils.circ',
349     'open-ils.circ.checkin',
350     $authtoken[1],
351     {barcode => CBARCODE}
352 );
353 subtest 'Check in after circulation' => sub{
354     plan tests => 3;
355     is(ref($checkin), 'HASH', 'Got event');
356     is($checkin->{textcode}, 'ROUTE_ITEM', 'Route item event');
357     is($checkin->{org}, BR1_ID, 'ROUTE_ITEM event destination');
358 };
359
360 # Check for transit.
361 $transit = $apputils->simplereq(
362     'open-ils.pcrud',
363     'open-ils.pcrud.search.atc',
364     $authtoken[1],
365     {target_copy => $copy->id(), source => BR3_ID, dest => BR1_ID, dest_recv_time => undef}
366 );
367 subtest 'Got transit after check in' => sub {
368     plan tests => 4;
369     isa_ok(ref($transit), 'Fieldmapper::action::transit_copy', 'Got transit copy');
370     is($transit->dest(), BR1_ID, 'Transit destination');
371     is($transit->source(), BR3_ID, 'Transit source');
372     is($transit->copy_status(), OILS_COPY_STATUS_RESHELVING, 'Transit copy status');
373 };
374
375 # Check copy status.
376 $copy = $apputils->simplereq(
377     'open-ils.pcrud',
378     'open-ils.pcrud.retrieve.acp',
379     $authtoken[1],
380     $copy->id()
381 );
382 is($copy->status(), OILS_COPY_STATUS_IN_TRANSIT, 'Copy in transit after check in');
383
384 # Abort the transit.
385 $abort = $apputils->simplereq(
386     'open-ils.circ',
387     'open-ils.circ.transit.abort',
388     $authtoken[0],
389     {transitid => $transit->id()}
390 );
391 is($abort, 1, 'Transit aborted');
392
393 # Check copy status.
394 $copy = $apputils->simplereq(
395     'open-ils.pcrud',
396     'open-ils.pcrud.retrieve.acp',
397     $authtoken[0],
398     $copy->id()
399 );
400 is($copy->status(), OILS_COPY_STATUS_CANCELED_TRANSIT, 'Copy is in Canceled Transit status');
401
402 # Logout at BR1.
403 $script->logout($authtoken[0]);
404
405 # Logout at BR3.
406 $script->logout($authtoken[1]);