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 OpenILS::Utils::DateTime qw/clean_ISO8601/;
21 our $apputils = 'OpenILS::Application::AppUtils';
23 #----------------------------------------------------------------
24 # The tests... assumes stock sample data
25 #----------------------------------------------------------------
27 my $storage_ses = $script->session('open-ils.storage');
28 my $circ_ses = $script->session('open-ils.circ');
29 my $cstore_ses = $script->session('open-ils.cstore');
31 my $user_req = $storage_ses->request('open-ils.storage.direct.actor.user.retrieve', 1);
32 if (my $user_resp = $user_req->recv) {
33 if (my $user = $user_resp->content) {
36 'Fieldmapper::actor::user',
37 'open-ils.storage.direct.actor.user.retrieve returned aou object'
42 'User with id = 1 is admin user'
47 my $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
48 if (my $item_resp = $item_req->recv) {
49 if (my $item = $item_resp->content) {
52 'Fieldmapper::asset::copy',
53 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
58 'Item with id = ' . ITEM_ID . ' has barcode ' . ITEM_BARCODE
61 $item->status == 7 || $item->status == 0,
62 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available'
67 $script->authenticate({
69 password => 'demo123',
75 my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
78 'Registered a new workstation'
82 $script->authenticate({
84 password => 'demo123',
86 workstation => WORKSTATION_NAME});
89 'Have an authtoken associated with the workstation'
92 my $checkout_resp = $script->do_checkout({
94 barcode => ITEM_BARCODE});
98 'Checkout request returned a HASH'
101 $checkout_resp->{ilsevent},
103 'Checkout returned a SUCCESS event'
106 ref $checkout_resp->{payload},
107 'Checkout response object has payload object'
110 ref $checkout_resp->{payload}->{circ},
111 'Payload object has circ object'
114 $checkout_resp->{payload}->{circ}->duration,
116 'Circ objection has loan duration of "7 days"'
119 my $circ = $checkout_resp->{payload}->{circ};
121 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
122 if (my $item_resp = $item_req->recv) {
123 if (my $item = $item_resp->content) {
127 'Item with id = ' . ITEM_ID . ' has status of Checked Out after fresh Storage request'
132 my $bill_req = $circ_ses->request(
133 'open-ils.circ.money.billing.retrieve.all',
137 if (my $bill_resp = $bill_req->recv) {
138 if (my $bills = $bill_resp->content) {
140 scalar( @{ $bills } ),
142 'Zero bills associated with circulation'
147 my $xact_start = DateTime::Format::ISO8601->parse_datetime(clean_ISO8601($circ->xact_start));
148 my $due_date = DateTime::Format::ISO8601->parse_datetime(clean_ISO8601($circ->due_date));
150 # Rewrite history; technically we should rewrite status_changed_item on the copy as well, but, meh...
151 $circ->xact_start( $xact_start->subtract( days => 20 )->iso8601() );
152 $circ->due_date( $due_date->subtract( days => 20 )->iso8601() );
154 $cstore_ses->connect; # need stateful connection
155 my $xact = $cstore_ses->request('open-ils.cstore.transaction.begin')->gather(1);
156 my $update_req = $cstore_ses->request(
157 'open-ils.cstore.direct.action.circulation.update',
160 if (my $update_resp = $update_req->gather(1)) {
162 'rewrote circ to have happened 20 days ago'
166 'rewrote circ to have happened 20 days ago'
169 $cstore_ses->request('open-ils.cstore.transaction.commit')->gather(1);
173 my $checkin_resp = $script->do_checkin({
174 barcode => ITEM_BARCODE});
178 'Checkin request returned a HASH'
181 $checkin_resp->{ilsevent},
183 'Checkin returned a SUCCESS event'
186 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
187 if (my $item_resp = $item_req->recv) {
188 if (my $item = $item_resp->content) {
190 $item->status == 7 || $item->status == 0,
191 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available after fresh Storage request'
196 $bill_req = $circ_ses->request(
197 'open-ils.circ.money.billing.retrieve.all',
201 if (my $bill_resp = $bill_req->recv) {
202 if (my $bills = $bill_resp->content) {
204 scalar( @{ $bills } ),
206 'Thirteen bills associated with circulation'