|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 2; |
22 |
use Test::More tests => 3; |
| 23 |
|
23 |
|
| 24 |
use Koha::Account; |
24 |
use Koha::Account; |
| 25 |
use Koha::Account::Lines; |
25 |
use Koha::Account::Lines; |
|
Lines 83-97
subtest 'outstanding_debits() tests' => sub {
Link Here
|
| 83 |
$schema->storage->txn_rollback; |
83 |
$schema->storage->txn_rollback; |
| 84 |
}; |
84 |
}; |
| 85 |
|
85 |
|
|
|
86 |
subtest 'outstanding_credits() tests' => sub { |
| 87 |
|
| 88 |
plan tests => 7; |
| 89 |
|
| 90 |
$schema->storage->txn_begin; |
| 91 |
|
| 92 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 93 |
my $account = $patron->account; |
| 94 |
|
| 95 |
my @generated_lines; |
| 96 |
push @generated_lines, $account->add_credit({ amount => 1 }); |
| 97 |
push @generated_lines, $account->add_credit({ amount => 2 }); |
| 98 |
push @generated_lines, $account->add_credit({ amount => 3 }); |
| 99 |
push @generated_lines, $account->add_credit({ amount => 4 }); |
| 100 |
|
| 101 |
my $lines = $account->outstanding_credits(); |
| 102 |
|
| 103 |
is( $lines->total_outstanding, -10, 'Outstandig credits total is correctly calculated' ); |
| 104 |
|
| 105 |
my $i = 0; |
| 106 |
foreach my $line ( @{ $lines->as_list } ) { |
| 107 |
my $fetched_line = Koha::Account::Lines->find( $generated_lines[$i]->id ); |
| 108 |
is_deeply( $line->unblessed, $fetched_line->unblessed, "Fetched line matches the generated one ($i)" ); |
| 109 |
$i++; |
| 110 |
} |
| 111 |
|
| 112 |
my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 113 |
$lines = $patron_2->account->outstanding_credits(); |
| 114 |
is( $lines->total_outstanding, 0, "Total if no outstanding credits is 0" ); |
| 115 |
is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" ); |
| 116 |
|
| 117 |
$schema->storage->txn_rollback; |
| 118 |
}; |
| 119 |
|
| 86 |
subtest 'add_credit() tests' => sub { |
120 |
subtest 'add_credit() tests' => sub { |
| 87 |
|
121 |
|
| 88 |
plan tests => 13; |
122 |
plan tests => 15; |
| 89 |
|
123 |
|
| 90 |
$schema->storage->txn_begin; |
124 |
$schema->storage->txn_begin; |
| 91 |
|
125 |
|
| 92 |
# delete logs and statistics |
126 |
# delete logs and statistics |
| 93 |
$schema->resultset('ActionLog')->search()->delete(); |
127 |
my $action_logs = $schema->resultset('ActionLog')->search()->count; |
| 94 |
$schema->resultset('Statistic')->search()->delete(); |
128 |
my $statistics = $schema->resultset('Statistic')->search()->count; |
| 95 |
|
129 |
|
| 96 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
130 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 97 |
my $account = Koha::Account->new( { patron_id => $patron->borrowernumber } ); |
131 |
my $account = Koha::Account->new( { patron_id => $patron->borrowernumber } ); |
|
Lines 106-118
subtest 'add_credit() tests' => sub {
Link Here
|
| 106 |
description => 'Payment of 25', |
140 |
description => 'Payment of 25', |
| 107 |
library_id => $patron->branchcode, |
141 |
library_id => $patron->branchcode, |
| 108 |
note => 'not really important', |
142 |
note => 'not really important', |
|
|
143 |
type => 'payment', |
| 109 |
user_id => $patron->id |
144 |
user_id => $patron->id |
| 110 |
} |
145 |
} |
| 111 |
); |
146 |
); |
| 112 |
|
147 |
|
| 113 |
is( $account->balance, -25, 'Patron has a balance of -25' ); |
148 |
is( $account->balance, -25, 'Patron has a balance of -25' ); |
| 114 |
is( $schema->resultset('ActionLog')->count(), 0, 'No log was added' ); |
149 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
| 115 |
is( $schema->resultset('Statistic')->count(), 1, 'Action added to statistics' ); |
150 |
is( $schema->resultset('Statistic')->count(), $statistics + 1, 'Action added to statistics' ); |
| 116 |
is( $line_1->accounttype, $Koha::Account::account_type->{'payment'}, 'Account type is correctly set' ); |
151 |
is( $line_1->accounttype, $Koha::Account::account_type->{'payment'}, 'Account type is correctly set' ); |
| 117 |
|
152 |
|
| 118 |
# Enable logs |
153 |
# Enable logs |
|
Lines 130-137
subtest 'add_credit() tests' => sub {
Link Here
|
| 130 |
); |
165 |
); |
| 131 |
|
166 |
|
| 132 |
is( $account->balance, -62, 'Patron has a balance of -25' ); |
167 |
is( $account->balance, -62, 'Patron has a balance of -25' ); |
| 133 |
is( $schema->resultset('ActionLog')->count(), 1, 'Log was added' ); |
168 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
| 134 |
is( $schema->resultset('Statistic')->count(), 2, 'Action added to statistics' ); |
169 |
is( $schema->resultset('Statistic')->count(), $statistics + 2, 'Action added to statistics' ); |
| 135 |
is( $line_2->accounttype, $Koha::Account::account_type->{'payment'} . $sip_code, 'Account type is correctly set' ); |
170 |
is( $line_2->accounttype, $Koha::Account::account_type->{'payment'} . $sip_code, 'Account type is correctly set' ); |
| 136 |
|
171 |
|
| 137 |
# offsets have the credit_id set to accountlines_id, and debit_id is undef |
172 |
# offsets have the credit_id set to accountlines_id, and debit_id is undef |
| 138 |
- |
|
|