]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/live_t/03-overdue_circ.t
LP#1670407 Add tests for xact_finish close/re-open
[working/Evergreen.git] / Open-ILS / src / perlmods / live_t / 03-overdue_circ.t
1 #!perl
2
3 use Test::More tests => 20;
4
5 diag("Test fine generation on checkin against the admin user.");
6
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;
11
12 use strict; use warnings;
13
14 use OpenILS::Utils::TestUtils;
15 my $script = OpenILS::Utils::TestUtils->new();
16
17 use DateTime;
18 use DateTime::Format::ISO8601;
19 use OpenSRF::Utils qw/cleanse_ISO8601/;
20
21 our $apputils = 'OpenILS::Application::AppUtils';
22
23 #----------------------------------------------------------------
24 # The tests...  assumes stock sample data, full-auto install by
25 # eg_wheezy_installer.sh, etc.
26 #----------------------------------------------------------------
27
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');
31
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) {
35         is(
36             ref $user,
37             'Fieldmapper::actor::user',
38             'open-ils.storage.direct.actor.user.retrieve returned aou object'
39         );
40         is(
41             $user->usrname,
42             'admin',
43             'User with id = 1 is admin user'
44         );
45     }
46 }
47
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) {
51         is(
52             ref $item,
53             'Fieldmapper::asset::copy',
54             'open-ils.storage.direct.asset.copy.retrieve returned acp object'
55         );
56         is(
57             $item->barcode,
58             ITEM_BARCODE,
59             'Item with id = ' . ITEM_ID . ' has barcode ' . ITEM_BARCODE
60         );
61         ok(
62             $item->status == 7 || $item->status == 0,
63             'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available'
64         );
65     }
66 }
67
68 $script->authenticate({
69     username => 'admin',
70     password => 'demo123',
71     type => 'staff'});
72 ok(
73     $script->authtoken,
74     'Have an authtoken'
75 );
76 my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
77 ok(
78     ! ref $ws,
79     'Registered a new workstation'
80 );
81
82 $script->logout();
83 $script->authenticate({
84     username => 'admin',
85     password => 'demo123',
86     type => 'staff',
87     workstation => WORKSTATION_NAME});
88 ok(
89     $script->authtoken,
90     'Have an authtoken associated with the workstation'
91 );
92
93 my $checkout_resp = $script->do_checkout({
94     patron => 1,
95     barcode => ITEM_BARCODE});
96 is(
97     ref $checkout_resp,
98     'HASH',
99     'Checkout request returned a HASH'
100 );
101 is(
102     $checkout_resp->{ilsevent},
103     0,
104     'Checkout returned a SUCCESS event'
105 );
106 ok(
107     ref $checkout_resp->{payload},
108     'Checkout response object has payload object'
109 );
110 ok(
111     ref $checkout_resp->{payload}->{circ},
112     'Payload object has circ object'
113 );
114 is(
115     $checkout_resp->{payload}->{circ}->duration,
116     '7 days',
117     'Circ objection has loan duration of "7 days"'
118 );
119
120 my $circ = $checkout_resp->{payload}->{circ};
121
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) {
125         is(
126             $item->status,
127             1,
128             'Item with id = ' . ITEM_ID . ' has status of Checked Out after fresh Storage request'
129         );
130     }
131 }
132
133 my $bill_req = $circ_ses->request(
134     'open-ils.circ.money.billing.retrieve.all',
135     $script->authtoken,
136     $circ->id
137 );
138 if (my $bill_resp = $bill_req->recv) {
139     if (my $bills = $bill_resp->content) {
140         is(
141             scalar( @{ $bills } ),
142             0,
143             'Zero bills associated with circulation'
144         );
145     }
146 }
147
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));
150
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() );
154
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',
159     $circ
160 );
161 if (my $update_resp = $update_req->gather(1)) {
162     pass(
163         'rewrote circ to have happened 20 days ago'
164     );
165 } else {
166     fail(
167         'rewrote circ to have happened 20 days ago'
168     );
169 }
170 $cstore_ses->request('open-ils.cstore.transaction.commit')->gather(1);
171
172 ########
173
174 my $checkin_resp = $script->do_checkin({
175     barcode => ITEM_BARCODE});
176 is(
177     ref $checkin_resp,
178     'HASH',
179     'Checkin request returned a HASH'
180 );
181 is(
182     $checkin_resp->{ilsevent},
183     0,
184     'Checkin returned a SUCCESS event'
185 );
186
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) {
190         ok(
191             $item->status == 7 || $item->status == 0,
192             'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available after fresh Storage request'
193         );
194     }
195 }
196
197 $bill_req = $circ_ses->request(
198     'open-ils.circ.money.billing.retrieve.all',
199     $script->authtoken,
200     $circ->id
201 );
202 if (my $bill_resp = $bill_req->recv) {
203     if (my $bills = $bill_resp->content) {
204         is(
205             scalar( @{ $bills } ),
206             13,
207             'Thirteen bills associated with circulation'
208         );
209     }
210 }
211
212
213 $script->logout();
214
215