3 use Test::More tests => 20;
5 diag("Test fine generation on checkin against the admin user.");
7 use constant WORKSTATION_NAME => 'BR4-test-03-overdue-circ.t';
8 use constant WORKSTATION_LIB => 7;
9 use constant ITEM_BARCODE => 'CONC71000345';
10 use constant ITEM_ID => 810;
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 #----------------------------------------------------------------
24 # The tests... assumes stock sample data, full-auto install by
25 # eg_wheezy_installer.sh, etc.
26 #----------------------------------------------------------------
28 my $storage_ses = $script->session('open-ils.storage');
29 my $circ_ses = $script->session('open-ils.circ');
30 my $cstore_ses = $script->session('open-ils.cstore');
32 my $user_req = $storage_ses->request('open-ils.storage.direct.actor.user.retrieve', 1);
33 if (my $user_resp = $user_req->recv) {
34 if (my $user = $user_resp->content) {
37 'Fieldmapper::actor::user',
38 'open-ils.storage.direct.actor.user.retrieve returned aou object'
43 'User with id = 1 is admin user'
48 my $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
49 if (my $item_resp = $item_req->recv) {
50 if (my $item = $item_resp->content) {
53 'Fieldmapper::asset::copy',
54 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
59 'Item with id = ' . ITEM_ID . ' has barcode ' . ITEM_BARCODE
62 $item->status == 7 || $item->status == 0,
63 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available'
68 $script->authenticate({
70 password => 'demo123',
76 my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
79 'Registered a new workstation'
83 $script->authenticate({
85 password => 'demo123',
87 workstation => WORKSTATION_NAME});
90 'Have an authtoken associated with the workstation'
93 my $checkout_resp = $script->do_checkout({
95 barcode => ITEM_BARCODE});
99 'Checkout request returned a HASH'
102 $checkout_resp->{ilsevent},
104 'Checkout returned a SUCCESS event'
107 ref $checkout_resp->{payload},
108 'Checkout response object has payload object'
111 ref $checkout_resp->{payload}->{circ},
112 'Payload object has circ object'
115 $checkout_resp->{payload}->{circ}->duration,
117 'Circ objection has loan duration of "7 days"'
120 my $circ = $checkout_resp->{payload}->{circ};
122 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
123 if (my $item_resp = $item_req->recv) {
124 if (my $item = $item_resp->content) {
128 'Item with id = ' . ITEM_ID . ' has status of Checked Out after fresh Storage request'
133 my $bill_req = $circ_ses->request(
134 'open-ils.circ.money.billing.retrieve.all',
138 if (my $bill_resp = $bill_req->recv) {
139 if (my $bills = $bill_resp->content) {
141 scalar( @{ $bills } ),
143 'Zero bills associated with circulation'
148 my $xact_start = DateTime::Format::ISO8601->parse_datetime(cleanse_ISO8601($circ->xact_start));
149 my $due_date = DateTime::Format::ISO8601->parse_datetime(cleanse_ISO8601($circ->due_date));
151 # Rewrite history; technically we should rewrite status_changed_item on the copy as well, but, meh...
152 $circ->xact_start( $xact_start->subtract( days => 20 )->iso8601() );
153 $circ->due_date( $due_date->subtract( days => 20 )->iso8601() );
155 $cstore_ses->connect; # need stateful connection
156 my $xact = $cstore_ses->request('open-ils.cstore.transaction.begin')->gather(1);
157 my $update_req = $cstore_ses->request(
158 'open-ils.cstore.direct.action.circulation.update',
161 if (my $update_resp = $update_req->gather(1)) {
163 'rewrote circ to have happened 20 days ago'
167 'rewrote circ to have happened 20 days ago'
170 $cstore_ses->request('open-ils.cstore.transaction.commit')->gather(1);
174 my $checkin_resp = $script->do_checkin({
175 barcode => ITEM_BARCODE});
179 'Checkin request returned a HASH'
182 $checkin_resp->{ilsevent},
184 'Checkin returned a SUCCESS event'
187 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
188 if (my $item_resp = $item_req->recv) {
189 if (my $item = $item_resp->content) {
191 $item->status == 7 || $item->status == 0,
192 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available after fresh Storage request'
197 $bill_req = $circ_ses->request(
198 'open-ils.circ.money.billing.retrieve.all',
202 if (my $bill_resp = $bill_req->recv) {
203 if (my $bills = $bill_resp->content) {
205 scalar( @{ $bills } ),
207 'Thirteen bills associated with circulation'