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 OpenILS::Utils::DateTime qw/clean_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
47 #----------------------------------------------------------------
49 my $storage_ses = $script->session('open-ils.storage');
52 my $user_req = $storage_ses->request('open-ils.storage.direct.actor.user.retrieve', USER_ID);
53 if (my $user_resp = $user_req->recv) {
54 if ($user_obj = $user_resp->content) {
57 'Fieldmapper::actor::user',
58 'open-ils.storage.direct.actor.user.retrieve returned aou object'
63 'User with id = ' . USER_ID . ' is ' . USER_USRNAME . ' user'
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 $summaries = fetch_billing_summaries();
96 scalar(@{ $summaries }),
98 'Two billable xacts for ' . USER_USRNAME . ' user from previous tests'
102 @{ $summaries }[0]->balance_owed + @{ $summaries }[1]->balance_owed,
104 'Both transactions combined have a balance owed of 1.25'
109 note => '05-pay_bills.t',
110 payment_type => 'cash_payment',
111 patron_credit => '0.00',
112 payments => [ map { [ $_->id, $_->balance_owed ] } @{ $summaries } ]
115 my $pay_resp = pay_bills($user_obj,$payment_blob);
120 'Payment attempt returned HASH'
124 scalar( @{ $pay_resp->{payments} } ),
126 'Payment response included two payment ids'
129 my $new_summaries = fetch_billing_summaries();
131 scalar(@{ $new_summaries }),
133 'Zero billable xacts for ' . USER_USRNAME . ' user after payment'