3 use Test::More tests => 22;
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 sub delete_closed_date {
50 my $resp = $apputils->simplereq(
52 'open-ils.actor.org_unit.closed.delete',
53 $script->authtoken, ref $aoucd ? $aoucd->id : $aoucd );
57 #----------------------------------------------------------------
58 # The tests... assumes stock sample data, full-auto install by
59 # eg_wheezy_installer.sh, etc.
60 #----------------------------------------------------------------
62 my $storage_ses = $script->session('open-ils.storage');
63 my $circ_ses = $script->session('open-ils.circ');
64 my $cstore_ses = $script->session('open-ils.cstore');
66 my $user_req = $storage_ses->request('open-ils.storage.direct.actor.user.retrieve', 1);
67 if (my $user_resp = $user_req->recv) {
68 if (my $user = $user_resp->content) {
71 'Fieldmapper::actor::user',
72 'open-ils.storage.direct.actor.user.retrieve returned aou object'
77 'User with id = 1 is admin user'
82 my $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
83 if (my $item_resp = $item_req->recv) {
84 if (my $item = $item_resp->content) {
87 'Fieldmapper::asset::copy',
88 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
93 'Item with id = ' . ITEM_ID . ' has barcode ' . ITEM_BARCODE
96 $item->status == 7 || $item->status == 0,
97 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available'
102 $script->authenticate({
104 password => 'demo123',
110 my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
113 'Registered a new workstation'
117 $script->authenticate({
119 password => 'demo123',
121 workstation => WORKSTATION_NAME});
124 'Have an authtoken associated with the workstation'
127 my $closed_date_obj = create_closed_date();
129 ref $closed_date_obj,
130 'Fieldmapper::actor::org_unit::closed_date',
131 'Created a closed date for 10 days ago'
134 my $checkout_resp = $script->do_checkout({
136 barcode => ITEM_BARCODE});
140 'Checkout request returned a HASH'
143 $checkout_resp->{ilsevent},
145 'Checkout returned a SUCCESS event'
148 ref $checkout_resp->{payload},
149 'Checkout response object has payload object'
152 ref $checkout_resp->{payload}->{circ},
153 'Payload object has circ object'
156 $checkout_resp->{payload}->{circ}->duration,
158 'Circ objection has loan duration of "7 days"'
161 my $circ = $checkout_resp->{payload}->{circ};
163 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
164 if (my $item_resp = $item_req->recv) {
165 if (my $item = $item_resp->content) {
169 'Item with id = ' . ITEM_ID . ' has status of Checked Out after fresh Storage request'
174 my $bill_req = $circ_ses->request(
175 'open-ils.circ.money.billing.retrieve.all',
179 if (my $bill_resp = $bill_req->recv) {
180 if (my $bills = $bill_resp->content) {
182 scalar( @{ $bills } ),
184 'Zero bills associated with circulation'
189 my $xact_start = DateTime::Format::ISO8601->parse_datetime(cleanse_ISO8601($circ->xact_start))->epoch;
190 my $due_date = DateTime::Format::ISO8601->parse_datetime(cleanse_ISO8601($circ->due_date))->epoch;
191 my $twenty_days = OpenSRF::Utils->interval_to_seconds('480 h 0 m 0 s');
193 # Rewrite history; technically we should rewrite status_changed_item on the copy as well, but, meh...
194 $circ->xact_start( $apputils->epoch2ISO8601($xact_start - $twenty_days) );
195 $circ->due_date( $apputils->epoch2ISO8601($due_date - $twenty_days) );
197 $cstore_ses->connect; # need stateful connection
198 my $xact = $cstore_ses->request('open-ils.cstore.transaction.begin')->gather(1);
199 my $update_req = $cstore_ses->request(
200 'open-ils.cstore.direct.action.circulation.update',
203 if (my $update_resp = $update_req->gather(1)) {
205 'rewrote circ to have happened 20 days ago'
209 'rewrote circ to have happened 20 days ago'
212 $cstore_ses->request('open-ils.cstore.transaction.commit')->gather(1);
216 my $checkin_resp = $script->do_checkin({
217 barcode => ITEM_BARCODE});
221 'Checkin request returned a HASH'
224 $checkin_resp->{ilsevent},
226 'Checkin returned a SUCCESS event'
229 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
230 if (my $item_resp = $item_req->recv) {
231 if (my $item = $item_resp->content) {
233 $item->status == 7 || $item->status == 0,
234 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available after fresh Storage request'
239 $bill_req = $circ_ses->request(
240 'open-ils.circ.money.billing.retrieve.all',
244 if (my $bill_resp = $bill_req->recv) {
245 if (my $bills = $bill_resp->content) {
247 scalar( @{ $bills } ),
249 'Twelve bills associated with circulation (instead of 13, thanks to closed date)'
254 my $tmp = delete_closed_date($closed_date_obj);
255 is($tmp, 1, 'Removed closed date');