3 use Test::More tests => 23;
5 diag("Test fine generation with closed date on checkin against the admin user.");
7 use constant WORKSTATION_NAME => 'BR4-test-04-overdue-with-closed-dates.t';
8 use constant WORKSTATION_LIB => 7;
9 use constant ITEM_BARCODE => 'CONC72000345';
10 use constant ITEM_ID => 1310;
12 use strict; use warnings;
14 use OpenILS::Utils::TestUtils;
15 my $script = OpenILS::Utils::TestUtils->new();
18 use DateTime::Format::ISO8601;
19 use OpenSRF::Utils qw/cleanse_ISO8601/;
21 our $apputils = "OpenILS::Application::AppUtils";
23 sub create_closed_date {
24 my $ten_days = OpenSRF::Utils->interval_to_seconds('240 h 0 m 0 s');
25 my $almost_twenty_four_hours = OpenSRF::Utils->interval_to_seconds('23 h 59 m 59 s');
26 #$circ->due_date( $apputils->epoch2ISO8601($due_date - $twenty_days) );
28 my $aoucd = Fieldmapper::actor::org_unit::closed_date->new;
29 $aoucd->org_unit(WORKSTATION_LIB);
30 $aoucd->reason('04-overdue_with_closed_dates.t');
32 $apputils->epoch2ISO8601(
33 DateTime->today()->epoch() - $ten_days
37 $apputils->epoch2ISO8601(
38 DateTime->today()->epoch() - $ten_days + $almost_twenty_four_hours
41 my $resp = $apputils->simplereq(
43 'open-ils.actor.org_unit.closed.create',
44 $script->authtoken, $aoucd);
48 # returns "1" on success, event on error
49 sub update_closed_date {
51 $aoucd->reason($aoucd->reason . ' modified');
52 return $apputils->simplereq(
54 'open-ils.actor.org_unit.closed.update',
55 $script->authtoken, $aoucd);
58 sub delete_closed_date {
60 my $resp = $apputils->simplereq(
62 'open-ils.actor.org_unit.closed.delete',
63 $script->authtoken, ref $aoucd ? $aoucd->id : $aoucd );
67 #----------------------------------------------------------------
68 # The tests... assumes stock sample data, full-auto install by
69 # eg_wheezy_installer.sh, etc.
70 #----------------------------------------------------------------
72 my $storage_ses = $script->session('open-ils.storage');
73 my $circ_ses = $script->session('open-ils.circ');
74 my $cstore_ses = $script->session('open-ils.cstore');
76 my $user_req = $storage_ses->request('open-ils.storage.direct.actor.user.retrieve', 1);
77 if (my $user_resp = $user_req->recv) {
78 if (my $user = $user_resp->content) {
81 'Fieldmapper::actor::user',
82 'open-ils.storage.direct.actor.user.retrieve returned aou object'
87 'User with id = 1 is admin user'
92 my $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
93 if (my $item_resp = $item_req->recv) {
94 if (my $item = $item_resp->content) {
97 'Fieldmapper::asset::copy',
98 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
103 'Item with id = ' . ITEM_ID . ' has barcode ' . ITEM_BARCODE
106 $item->status == 7 || $item->status == 0,
107 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available'
112 $script->authenticate({
114 password => 'demo123',
120 my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
123 'Registered a new workstation'
127 $script->authenticate({
129 password => 'demo123',
131 workstation => WORKSTATION_NAME});
134 'Have an authtoken associated with the workstation'
137 my $closed_date_obj = create_closed_date();
139 ref $closed_date_obj,
140 'Fieldmapper::actor::org_unit::closed_date',
141 'Created a closed date for 10 days ago'
145 update_closed_date($closed_date_obj),
147 'Updated closed date reason'
150 my $checkout_resp = $script->do_checkout({
152 barcode => ITEM_BARCODE});
156 'Checkout request returned a HASH'
159 $checkout_resp->{ilsevent},
161 'Checkout returned a SUCCESS event'
164 ref $checkout_resp->{payload},
165 'Checkout response object has payload object'
168 ref $checkout_resp->{payload}->{circ},
169 'Payload object has circ object'
172 $checkout_resp->{payload}->{circ}->duration,
174 'Circ objection has loan duration of "7 days"'
177 my $circ = $checkout_resp->{payload}->{circ};
179 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
180 if (my $item_resp = $item_req->recv) {
181 if (my $item = $item_resp->content) {
185 'Item with id = ' . ITEM_ID . ' has status of Checked Out after fresh Storage request'
190 my $bill_req = $circ_ses->request(
191 'open-ils.circ.money.billing.retrieve.all',
195 if (my $bill_resp = $bill_req->recv) {
196 if (my $bills = $bill_resp->content) {
198 scalar( @{ $bills } ),
200 'Zero bills associated with circulation'
205 my $xact_start = DateTime::Format::ISO8601->parse_datetime(cleanse_ISO8601($circ->xact_start))->epoch;
206 my $due_date = DateTime::Format::ISO8601->parse_datetime(cleanse_ISO8601($circ->due_date))->epoch;
207 my $twenty_days = OpenSRF::Utils->interval_to_seconds('480 h 0 m 0 s');
209 # Rewrite history; technically we should rewrite status_changed_item on the copy as well, but, meh...
210 $circ->xact_start( $apputils->epoch2ISO8601($xact_start - $twenty_days) );
211 $circ->due_date( $apputils->epoch2ISO8601($due_date - $twenty_days) );
213 $cstore_ses->connect; # need stateful connection
214 my $xact = $cstore_ses->request('open-ils.cstore.transaction.begin')->gather(1);
215 my $update_req = $cstore_ses->request(
216 'open-ils.cstore.direct.action.circulation.update',
219 if (my $update_resp = $update_req->gather(1)) {
221 'rewrote circ to have happened 20 days ago'
225 'rewrote circ to have happened 20 days ago'
228 $cstore_ses->request('open-ils.cstore.transaction.commit')->gather(1);
232 my $checkin_resp = $script->do_checkin({
233 barcode => ITEM_BARCODE});
237 'Checkin request returned a HASH'
240 $checkin_resp->{ilsevent},
242 'Checkin returned a SUCCESS event'
245 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
246 if (my $item_resp = $item_req->recv) {
247 if (my $item = $item_resp->content) {
249 $item->status == 7 || $item->status == 0,
250 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available after fresh Storage request'
255 $bill_req = $circ_ses->request(
256 'open-ils.circ.money.billing.retrieve.all',
260 if (my $bill_resp = $bill_req->recv) {
261 if (my $bills = $bill_resp->content) {
263 scalar( @{ $bills } ),
265 'Twelve bills associated with circulation (instead of 13, thanks to closed date)'
270 my $tmp = delete_closed_date($closed_date_obj);
271 is($tmp, 1, 'Removed closed date');