3 use Test::More tests => 10;
5 diag("Test bill payment against the admin user.");
7 use constant WORKSTATION_NAME => 'BR4-test-05-pay-bills.t';
8 use constant WORKSTATION_LIB => 7;
9 use constant USER_ID => 1;
10 use constant USER_USRNAME => 'admin';
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 fetch_billing_summaries {
24 my $resp = $apputils->simplereq(
26 'open-ils.actor.user.transactions.history.have_balance.authoritative',
34 my ($user_obj, $payment_blob) = (shift, shift);
35 my $resp = $apputils->simplereq(
37 'open-ils.circ.money.payment',
40 $user_obj->last_xact_id
45 #----------------------------------------------------------------
46 # The tests... assumes stock sample data, full-auto install by
47 # eg_wheezy_installer.sh, etc.
48 #----------------------------------------------------------------
50 my $storage_ses = $script->session('open-ils.storage');
53 my $user_req = $storage_ses->request('open-ils.storage.direct.actor.user.retrieve', USER_ID);
54 if (my $user_resp = $user_req->recv) {
55 if ($user_obj = $user_resp->content) {
58 'Fieldmapper::actor::user',
59 'open-ils.storage.direct.actor.user.retrieve returned aou object'
64 'User with id = ' . USER_ID . ' is ' . USER_USRNAME . ' user'
69 $script->authenticate({
71 password => 'demo123',
77 my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
80 'Registered a new workstation'
84 $script->authenticate({
86 password => 'demo123',
88 workstation => WORKSTATION_NAME});
91 'Have an authtoken associated with the workstation'
94 my $summaries = fetch_billing_summaries();
97 scalar(@{ $summaries }),
99 'Two billable xacts for ' . USER_USRNAME . ' user from previous tests'
103 @{ $summaries }[0]->balance_owed + @{ $summaries }[1]->balance_owed,
105 'Both transactions combined have a balance owed of 1.25'
110 note => '05-pay_bills.t',
111 payment_type => 'cash_payment',
112 patron_credit => '0.00',
113 payments => [ map { [ $_->id, $_->balance_owed ] } @{ $summaries } ]
116 my $pay_resp = pay_bills($user_obj,$payment_blob);
121 'Payment attempt returned HASH'
125 scalar( @{ $pay_resp->{payments} } ),
127 'Payment response included two payment ids'
130 my $new_summaries = fetch_billing_summaries();
132 scalar(@{ $new_summaries }),
134 'Zero billable xacts for ' . USER_USRNAME . ' user after payment'