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;
16 use OpenSRF::AppSession;
17 use Digest::MD5 qw(md5_hex);
18 use OpenILS::Utils::Fieldmapper;
19 use OpenILS::Application::AppUtils;
21 use DateTime::Format::ISO8601;
22 use OpenSRF::Utils qw/cleanse_ISO8601/;
23 use OpenSRF::Utils::SettingsClient;
26 our $cache = "OpenSRF::Utils::Cache";
27 our $apputils = "OpenILS::Application::AppUtils";
32 #----------------------------------------------------------------
34 #----------------------------------------------------------------
36 my ($pkg, $file, $line, $sub) = _caller();
38 die "Script halted with error ".
39 "($pkg : $file : $line : $sub):\n" . shift() . "\n";
42 #----------------------------------------------------------------
43 # This is not the function you're looking for
44 #----------------------------------------------------------------
46 my ($pkg, $file, $line, $sub) = caller(2);
48 ($pkg, $file, $line) = caller(1);
51 return ($pkg, $file, $line, $sub);
54 #----------------------------------------------------------------
55 # Connect to the servers
56 #----------------------------------------------------------------
58 my $config = `osrf_config --sysconfdir`;
60 $config .= '/opensrf_core.xml';
61 err("Bootstrap config required") unless $config;
62 OpenSRF::System->bootstrap_client( config_file => $config );
63 Fieldmapper->import(IDL =>
64 OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
67 #----------------------------------------------------------------
68 # Is the given object an OILS event?
69 #----------------------------------------------------------------
72 if( $e and ref($e) eq 'HASH' ) {
73 return 1 if defined($e->{ilsevent});
78 #----------------------------------------------------------------
79 # If the given object is an event, this prints the event info
80 # and exits the script
81 #----------------------------------------------------------------
84 my ($pkg, $file, $line, $sub) = _caller();
85 if(oils_is_event($evt)) {
86 if($evt->{ilsevent}) {
87 diag("\nReceived Event($pkg : $file : $line : $sub): \n" . Dumper($evt));
93 #----------------------------------------------------------------
94 # Login to the auth server and set the global $authtoken var
95 #----------------------------------------------------------------
97 my( $username, $password, $type, $ws ) = @_;
101 my $seed = $apputils->simplereq( 'open-ils.auth',
102 'open-ils.auth.authenticate.init', $username );
103 err("No auth seed") unless $seed;
105 my $response = $apputils->simplereq( 'open-ils.auth',
106 'open-ils.auth.authenticate.complete',
107 { username => $username,
108 password => md5_hex($seed . md5_hex($password)),
109 type => $type, workstation => $ws });
111 err("No auth response returned on login") unless $response;
113 oils_event_die($response);
115 $authtime = $response->{payload}->{authtime};
116 $authtoken = $response->{payload}->{authtoken};
117 diag("authtime is $authtime, authtoken is $authtoken");
121 #----------------------------------------------------------------
122 # Destroys the login session on the server
123 #----------------------------------------------------------------
125 $apputils->simplereq(
127 'open-ils.auth.session.delete', (@_ ? shift : $authtoken) );
130 #----------------------------------------------------------------
131 # var $response = simplereq( $service, $method, @params );
132 #----------------------------------------------------------------
133 sub simplereq { return $apputils->simplereq(@_); }
134 sub osrf_request { return $apputils->simplereq(@_); }
136 #----------------------------------------------------------------
138 sub register_workstation {
139 my $resp = osrf_request(
141 'open-ils.actor.workstation.register',
142 $authtoken, WORKSTATION_NAME, WORKSTATION_LIB);
147 my( $patronid, $barcode ) = @_;
148 my $args = { patron => $patronid, barcode => $barcode };
149 my $resp = osrf_request(
151 'open-ils.circ.checkout.full', $authtoken, $args );
157 my $args = { barcode => $barcode };
158 my $resp = osrf_request(
160 'open-ils.circ.checkin', $authtoken, $args );
164 #----------------------------------------------------------------
165 # The tests... assumes stock sample data, full-auto install by
166 # eg_wheezy_installer.sh, etc.
167 #----------------------------------------------------------------
170 my $storage_ses = OpenSRF::AppSession->create('open-ils.storage');
171 my $circ_ses = OpenSRF::AppSession->create('open-ils.circ');
172 my $cstore_ses = OpenSRF::AppSession->connect('open-ils.cstore');
174 my $user_req = $storage_ses->request('open-ils.storage.direct.actor.user.retrieve', 1);
175 if (my $user_resp = $user_req->recv) {
176 if (my $user = $user_resp->content) {
179 'Fieldmapper::actor::user',
180 'open-ils.storage.direct.actor.user.retrieve returned aou object'
185 'User with id = 1 is admin user'
190 my $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
191 if (my $item_resp = $item_req->recv) {
192 if (my $item = $item_resp->content) {
195 'Fieldmapper::asset::copy',
196 'open-ils.storage.direct.asset.copy.retrieve returned acp object'
201 'Item with id = ' . ITEM_ID . ' has barcode ' . ITEM_BARCODE
204 $item->status == 7 || $item->status == 0,
205 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available'
210 oils_login('admin','demo123','staff');
215 my $ws = register_workstation();
218 'Registered a new workstation'
222 oils_login('admin','demo123','staff',WORKSTATION_NAME);
225 'Have an authtoken associated with the workstation'
228 my $checkout_resp = do_checkout(1, ITEM_BARCODE);
232 'Checkout request returned a HASH'
235 $checkout_resp->{ilsevent},
237 'Checkout returned a SUCCESS event'
240 ref $checkout_resp->{payload},
241 'Checkout response object has payload object'
244 ref $checkout_resp->{payload}->{circ},
245 'Payload object has circ object'
248 $checkout_resp->{payload}->{circ}->duration,
250 'Circ objection has loan duration of "7 days"'
253 my $circ = $checkout_resp->{payload}->{circ};
255 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
256 if (my $item_resp = $item_req->recv) {
257 if (my $item = $item_resp->content) {
261 'Item with id = ' . ITEM_ID . ' has status of Checked Out after fresh Storage request'
266 my $bill_req = $circ_ses->request(
267 'open-ils.circ.money.billing.retrieve.all',
271 if (my $bill_resp = $bill_req->recv) {
272 if (my $bills = $bill_resp->content) {
274 scalar( @{ $bills } ),
276 'Zero bills associated with circulation'
281 my $xact_start = DateTime::Format::ISO8601->parse_datetime(cleanse_ISO8601($circ->xact_start))->epoch;
282 my $due_date = DateTime::Format::ISO8601->parse_datetime(cleanse_ISO8601($circ->due_date))->epoch;
283 my $twenty_days = OpenSRF::Utils->interval_to_seconds('480 h 0 m 0 s');
285 # Rewrite history; technically we should rewrite status_changed_item on the copy as well, but, meh...
286 $circ->xact_start( $apputils->epoch2ISO8601($xact_start - $twenty_days) );
287 $circ->due_date( $apputils->epoch2ISO8601($due_date - $twenty_days) );
289 my $xact = $cstore_ses->request('open-ils.cstore.transaction.begin')->gather(1);
290 my $update_req = $cstore_ses->request(
291 'open-ils.cstore.direct.action.circulation.update',
294 if (my $update_resp = $update_req->gather(1)) {
296 'rewrote circ to have happened 20 days ago'
300 'rewrote circ to have happened 20 days ago'
303 $cstore_ses->request('open-ils.cstore.transaction.commit')->gather(1);
307 my $checkin_resp = do_checkin(ITEM_BARCODE);
311 'Checkin request returned a HASH'
314 $checkin_resp->{ilsevent},
316 'Checkin returned a SUCCESS event'
319 $item_req = $storage_ses->request('open-ils.storage.direct.asset.copy.retrieve', ITEM_ID);
320 if (my $item_resp = $item_req->recv) {
321 if (my $item = $item_resp->content) {
323 $item->status == 7 || $item->status == 0,
324 'Item with id = ' . ITEM_ID . ' has status of Reshelving or Available after fresh Storage request'
329 $bill_req = $circ_ses->request(
330 'open-ils.circ.money.billing.retrieve.all',
334 if (my $bill_resp = $bill_req->recv) {
335 if (my $bills = $bill_resp->content) {
337 scalar( @{ $bills } ),
339 'Thirteen bills associated with circulation'