Lines 201-207
subtest 'outstanding_credits() tests' => sub {
Link Here
|
201 |
|
201 |
|
202 |
subtest 'add_credit() tests' => sub { |
202 |
subtest 'add_credit() tests' => sub { |
203 |
|
203 |
|
204 |
plan tests => 17; |
204 |
plan tests => 21; |
205 |
|
205 |
|
206 |
$schema->storage->txn_begin; |
206 |
$schema->storage->txn_begin; |
207 |
|
207 |
|
Lines 219-225
subtest 'add_credit() tests' => sub {
Link Here
|
219 |
|
219 |
|
220 |
throws_ok { |
220 |
throws_ok { |
221 |
$account->add_credit( |
221 |
$account->add_credit( |
222 |
{ amount => 25, |
222 |
{ |
|
|
223 |
amount => 25, |
223 |
description => 'Payment of 25', |
224 |
description => 'Payment of 25', |
224 |
library_id => $patron->branchcode, |
225 |
library_id => $patron->branchcode, |
225 |
note => 'not really important', |
226 |
note => 'not really important', |
Lines 231-237
subtest 'add_credit() tests' => sub {
Link Here
|
231 |
'Koha::Exceptions::MissingParameter', 'Exception thrown if interface parameter missing'; |
232 |
'Koha::Exceptions::MissingParameter', 'Exception thrown if interface parameter missing'; |
232 |
|
233 |
|
233 |
my $line_1 = $account->add_credit( |
234 |
my $line_1 = $account->add_credit( |
234 |
{ amount => 25, |
235 |
{ |
|
|
236 |
amount => 25, |
235 |
description => 'Payment of 25', |
237 |
description => 'Payment of 25', |
236 |
library_id => $patron->branchcode, |
238 |
library_id => $patron->branchcode, |
237 |
note => 'not really important', |
239 |
note => 'not really important', |
Lines 245-250
subtest 'add_credit() tests' => sub {
Link Here
|
245 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
247 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
246 |
is( $schema->resultset('Statistic')->count(), $statistics + 1, 'Action added to statistics' ); |
248 |
is( $schema->resultset('Statistic')->count(), $statistics + 1, 'Action added to statistics' ); |
247 |
is( $line_1->credit_type_code, 'PAYMENT', 'Account type is correctly set' ); |
249 |
is( $line_1->credit_type_code, 'PAYMENT', 'Account type is correctly set' ); |
|
|
250 |
ok( $line_1->amount < 0, 'Credit amount is stored as a negative' ); |
248 |
|
251 |
|
249 |
# Enable logs |
252 |
# Enable logs |
250 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
253 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
Lines 263-268
subtest 'add_credit() tests' => sub {
Link Here
|
263 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
266 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
264 |
is( $schema->resultset('Statistic')->count(), $statistics + 2, 'Action added to statistics' ); |
267 |
is( $schema->resultset('Statistic')->count(), $statistics + 2, 'Action added to statistics' ); |
265 |
is( $line_2->credit_type_code, 'PAYMENT', 'Account type is correctly set' ); |
268 |
is( $line_2->credit_type_code, 'PAYMENT', 'Account type is correctly set' ); |
|
|
269 |
ok( $line_1->amount < 0, 'Credit amount is stored as a negative' ); |
266 |
|
270 |
|
267 |
# offsets have the credit_id set to accountlines_id, and debit_id is undef |
271 |
# offsets have the credit_id set to accountlines_id, and debit_id is undef |
268 |
my $offset_1 = Koha::Account::Offsets->search({ credit_id => $line_1->id })->next; |
272 |
my $offset_1 = Koha::Account::Offsets->search({ credit_id => $line_1->id })->next; |
Lines 270-277
subtest 'add_credit() tests' => sub {
Link Here
|
270 |
|
274 |
|
271 |
is( $offset_1->credit_id, $line_1->id, 'No debit_id is set for credits' ); |
275 |
is( $offset_1->credit_id, $line_1->id, 'No debit_id is set for credits' ); |
272 |
is( $offset_1->debit_id, undef, 'No debit_id is set for credits' ); |
276 |
is( $offset_1->debit_id, undef, 'No debit_id is set for credits' ); |
|
|
277 |
ok( $offset_1->amount > 0, 'Credit creation offset is a positive' ); |
273 |
is( $offset_2->credit_id, $line_2->id, 'No debit_id is set for credits' ); |
278 |
is( $offset_2->credit_id, $line_2->id, 'No debit_id is set for credits' ); |
274 |
is( $offset_2->debit_id, undef, 'No debit_id is set for credits' ); |
279 |
is( $offset_2->debit_id, undef, 'No debit_id is set for credits' ); |
|
|
280 |
ok( $offset_2->amount > 0, 'Credit creation offset is a positive' ); |
275 |
|
281 |
|
276 |
my $line_3 = $account->add_credit( |
282 |
my $line_3 = $account->add_credit( |
277 |
{ |
283 |
{ |
Lines 1392-1398
subtest 'Koha::Account::payin_amount() tests' => sub {
Link Here
|
1392 |
is( $offsets->count, 4, 'Four offsets generated' ); |
1398 |
is( $offsets->count, 4, 'Four offsets generated' ); |
1393 |
my $offset = $offsets->next; |
1399 |
my $offset = $offsets->next; |
1394 |
is( $offset->type, 'CREATE', 'CREATE offset added for payin line' ); |
1400 |
is( $offset->type, 'CREATE', 'CREATE offset added for payin line' ); |
1395 |
is( $offset->amount * 1, -10, 'Correct offset amount recorded' ); |
1401 |
is( $offset->amount * 1, 10, 'Correct offset amount recorded' ); |
1396 |
$offset = $offsets->next; |
1402 |
$offset = $offsets->next; |
1397 |
is( $offset->debit_id, $debit_1->id, "Offset added against debit_1"); |
1403 |
is( $offset->debit_id, $debit_1->id, "Offset added against debit_1"); |
1398 |
is( $offset->type, 'APPLY', "APPLY used for offset_type" ); |
1404 |
is( $offset->type, 'APPLY', "APPLY used for offset_type" ); |
Lines 1425-1431
subtest 'Koha::Account::payin_amount() tests' => sub {
Link Here
|
1425 |
is( $offsets->count, 2, 'Two offsets generated' ); |
1431 |
is( $offsets->count, 2, 'Two offsets generated' ); |
1426 |
$offset = $offsets->next; |
1432 |
$offset = $offsets->next; |
1427 |
is( $offset->type, 'CREATE', 'CREATE offset added for payin line' ); |
1433 |
is( $offset->type, 'CREATE', 'CREATE offset added for payin line' ); |
1428 |
is( $offset->amount * 1, -2.50, 'Correct offset amount recorded' ); |
1434 |
is( $offset->amount * 1, 2.50, 'Correct offset amount recorded' ); |
1429 |
$offset = $offsets->next; |
1435 |
$offset = $offsets->next; |
1430 |
is( $offset->debit_id, $debit_5->id, "Offset added against debit_5"); |
1436 |
is( $offset->debit_id, $debit_5->id, "Offset added against debit_5"); |
1431 |
is( $offset->type, 'APPLY', "APPLY used for offset_type" ); |
1437 |
is( $offset->type, 'APPLY', "APPLY used for offset_type" ); |
1432 |
- |
|
|