Lines 19-26
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 7; |
23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
|
|
24 |
use Test::Exception; |
24 |
|
25 |
|
25 |
use Koha::Account; |
26 |
use Koha::Account; |
26 |
use Koha::Account::Lines; |
27 |
use Koha::Account::Lines; |
Lines 149-155
subtest 'add_credit() tests' => sub {
Link Here
|
149 |
is( $account->balance, -25, 'Patron has a balance of -25' ); |
150 |
is( $account->balance, -25, 'Patron has a balance of -25' ); |
150 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
151 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
151 |
is( $schema->resultset('Statistic')->count(), $statistics + 1, 'Action added to statistics' ); |
152 |
is( $schema->resultset('Statistic')->count(), $statistics + 1, 'Action added to statistics' ); |
152 |
is( $line_1->accounttype, $Koha::Account::account_type->{'payment'}, 'Account type is correctly set' ); |
153 |
is( $line_1->accounttype, $Koha::Account::account_type_credit->{'payment'}, 'Account type is correctly set' ); |
153 |
|
154 |
|
154 |
# Enable logs |
155 |
# Enable logs |
155 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
156 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
Lines 168-174
subtest 'add_credit() tests' => sub {
Link Here
|
168 |
is( $account->balance, -62, 'Patron has a balance of -25' ); |
169 |
is( $account->balance, -62, 'Patron has a balance of -25' ); |
169 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
170 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
170 |
is( $schema->resultset('Statistic')->count(), $statistics + 2, 'Action added to statistics' ); |
171 |
is( $schema->resultset('Statistic')->count(), $statistics + 2, 'Action added to statistics' ); |
171 |
is( $line_2->accounttype, $Koha::Account::account_type->{'payment'} . $sip_code, 'Account type is correctly set' ); |
172 |
is( $line_2->accounttype, $Koha::Account::account_type_credit->{'payment'} . $sip_code, 'Account type is correctly set' ); |
172 |
|
173 |
|
173 |
# offsets have the credit_id set to accountlines_id, and debit_id is undef |
174 |
# offsets have the credit_id set to accountlines_id, and debit_id is undef |
174 |
my $offset_1 = Koha::Account::Offsets->search({ credit_id => $line_1->id })->next; |
175 |
my $offset_1 = Koha::Account::Offsets->search({ credit_id => $line_1->id })->next; |
Lines 194-199
subtest 'add_credit() tests' => sub {
Link Here
|
194 |
$schema->storage->txn_rollback; |
195 |
$schema->storage->txn_rollback; |
195 |
}; |
196 |
}; |
196 |
|
197 |
|
|
|
198 |
subtest 'add_debit() tests' => sub { |
199 |
|
200 |
plan tests => 13; |
201 |
|
202 |
$schema->storage->txn_begin; |
203 |
|
204 |
# delete logs and statistics |
205 |
my $action_logs = $schema->resultset('ActionLog')->search()->count; |
206 |
my $statistics = $schema->resultset('Statistic')->search()->count; |
207 |
|
208 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
209 |
my $account = |
210 |
Koha::Account->new( { patron_id => $patron->borrowernumber } ); |
211 |
|
212 |
is( $account->balance, 0, 'Patron has no balance' ); |
213 |
|
214 |
throws_ok { |
215 |
$account->add_debit( |
216 |
{ |
217 |
amount => -5, |
218 |
description => 'amount validation failure', |
219 |
library_id => $patron->branchcode, |
220 |
note => 'this should fail anyway', |
221 |
type => 'rent', |
222 |
user_id => $patron->id |
223 |
} |
224 |
); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)'; |
225 |
|
226 |
throws_ok { |
227 |
$account->add_debit( |
228 |
{ |
229 |
amount => 5, |
230 |
description => 'type validation failure', |
231 |
library_id => $patron->branchcode, |
232 |
note => 'this should fail anyway', |
233 |
type => 'failure', |
234 |
user_id => $patron->id |
235 |
} |
236 |
); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)'; |
237 |
|
238 |
# Disable logs |
239 |
t::lib::Mocks::mock_preference( 'FinesLog', 0 ); |
240 |
|
241 |
my $line_1 = $account->add_debit( |
242 |
{ |
243 |
amount => 25, |
244 |
description => 'Rental charge of 25', |
245 |
library_id => $patron->branchcode, |
246 |
note => 'not really important', |
247 |
type => 'rent', |
248 |
user_id => $patron->id |
249 |
} |
250 |
); |
251 |
|
252 |
is( $account->balance, 25, 'Patron has a balance of 25' ); |
253 |
is( |
254 |
$schema->resultset('ActionLog')->count(), |
255 |
$action_logs + 0, |
256 |
'No log was added' |
257 |
); |
258 |
is( |
259 |
$line_1->accounttype, |
260 |
$Koha::Account::account_type_debit->{'rent'}, |
261 |
'Account type is correctly set' |
262 |
); |
263 |
|
264 |
# Enable logs |
265 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
266 |
|
267 |
my $sip_code = "1"; |
268 |
my $line_2 = $account->add_debit( |
269 |
{ |
270 |
amount => 37, |
271 |
description => 'Rental charge of 37', |
272 |
library_id => $patron->branchcode, |
273 |
note => 'not really important', |
274 |
type => 'rent', |
275 |
user_id => $patron->id, |
276 |
} |
277 |
); |
278 |
|
279 |
is( $account->balance, 62, 'Patron has a balance of 62' ); |
280 |
is( |
281 |
$schema->resultset('ActionLog')->count(), |
282 |
$action_logs + 1, |
283 |
'Log was added' |
284 |
); |
285 |
is( |
286 |
$line_2->accounttype, |
287 |
$Koha::Account::account_type_debit->{'rent'}, |
288 |
'Account type is correctly set' |
289 |
); |
290 |
|
291 |
# offsets have the debit_id set to accountlines_id, and credit_id is undef |
292 |
my $offset_1 = |
293 |
Koha::Account::Offsets->search( { debit_id => $line_1->id } )->next; |
294 |
my $offset_2 = |
295 |
Koha::Account::Offsets->search( { debit_id => $line_2->id } )->next; |
296 |
|
297 |
is( $offset_1->debit_id, $line_1->id, 'debit_id is set for debit 1' ); |
298 |
is( $offset_1->credit_id, undef, 'credit_id is not set for debit 1' ); |
299 |
is( $offset_2->debit_id, $line_2->id, 'debit_id is set for debit 2' ); |
300 |
is( $offset_2->credit_id, undef, 'credit_id is not set for debit 2' ); |
301 |
|
302 |
$schema->storage->txn_rollback; |
303 |
}; |
304 |
|
197 |
subtest 'lines() tests' => sub { |
305 |
subtest 'lines() tests' => sub { |
198 |
|
306 |
|
199 |
plan tests => 1; |
307 |
plan tests => 1; |
200 |
- |
|
|