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 169-175
subtest 'add_credit() tests' => sub {
Link Here
|
169 |
is( $account->balance, -25, 'Patron has a balance of -25' ); |
170 |
is( $account->balance, -25, 'Patron has a balance of -25' ); |
170 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
171 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
171 |
is( $schema->resultset('Statistic')->count(), $statistics + 1, 'Action added to statistics' ); |
172 |
is( $schema->resultset('Statistic')->count(), $statistics + 1, 'Action added to statistics' ); |
172 |
is( $line_1->accounttype, $Koha::Account::account_type->{'payment'}, 'Account type is correctly set' ); |
173 |
is( $line_1->accounttype, $Koha::Account::account_type_credit->{'payment'}, 'Account type is correctly set' ); |
173 |
|
174 |
|
174 |
# Enable logs |
175 |
# Enable logs |
175 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
176 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
Lines 188-194
subtest 'add_credit() tests' => sub {
Link Here
|
188 |
is( $account->balance, -62, 'Patron has a balance of -25' ); |
189 |
is( $account->balance, -62, 'Patron has a balance of -25' ); |
189 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
190 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
190 |
is( $schema->resultset('Statistic')->count(), $statistics + 2, 'Action added to statistics' ); |
191 |
is( $schema->resultset('Statistic')->count(), $statistics + 2, 'Action added to statistics' ); |
191 |
is( $line_2->accounttype, $Koha::Account::account_type->{'payment'} . $sip_code, 'Account type is correctly set' ); |
192 |
is( $line_2->accounttype, $Koha::Account::account_type_credit->{'payment'} . $sip_code, 'Account type is correctly set' ); |
192 |
|
193 |
|
193 |
# offsets have the credit_id set to accountlines_id, and debit_id is undef |
194 |
# offsets have the credit_id set to accountlines_id, and debit_id is undef |
194 |
my $offset_1 = Koha::Account::Offsets->search({ credit_id => $line_1->id })->next; |
195 |
my $offset_1 = Koha::Account::Offsets->search({ credit_id => $line_1->id })->next; |
Lines 214-219
subtest 'add_credit() tests' => sub {
Link Here
|
214 |
$schema->storage->txn_rollback; |
215 |
$schema->storage->txn_rollback; |
215 |
}; |
216 |
}; |
216 |
|
217 |
|
|
|
218 |
subtest 'add_debit() tests' => sub { |
219 |
|
220 |
plan tests => 13; |
221 |
|
222 |
$schema->storage->txn_begin; |
223 |
|
224 |
# delete logs and statistics |
225 |
my $action_logs = $schema->resultset('ActionLog')->search()->count; |
226 |
my $statistics = $schema->resultset('Statistic')->search()->count; |
227 |
|
228 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
229 |
my $account = |
230 |
Koha::Account->new( { patron_id => $patron->borrowernumber } ); |
231 |
|
232 |
is( $account->balance, 0, 'Patron has no balance' ); |
233 |
|
234 |
throws_ok { |
235 |
$account->add_debit( |
236 |
{ |
237 |
amount => -5, |
238 |
description => 'amount validation failure', |
239 |
library_id => $patron->branchcode, |
240 |
note => 'this should fail anyway', |
241 |
type => 'rent', |
242 |
user_id => $patron->id |
243 |
} |
244 |
); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)'; |
245 |
|
246 |
throws_ok { |
247 |
$account->add_debit( |
248 |
{ |
249 |
amount => 5, |
250 |
description => 'type validation failure', |
251 |
library_id => $patron->branchcode, |
252 |
note => 'this should fail anyway', |
253 |
type => 'failure', |
254 |
user_id => $patron->id |
255 |
} |
256 |
); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)'; |
257 |
|
258 |
# Disable logs |
259 |
t::lib::Mocks::mock_preference( 'FinesLog', 0 ); |
260 |
|
261 |
my $line_1 = $account->add_debit( |
262 |
{ |
263 |
amount => 25, |
264 |
description => 'Rental charge of 25', |
265 |
library_id => $patron->branchcode, |
266 |
note => 'not really important', |
267 |
type => 'rent', |
268 |
user_id => $patron->id |
269 |
} |
270 |
); |
271 |
|
272 |
is( $account->balance, 25, 'Patron has a balance of 25' ); |
273 |
is( |
274 |
$schema->resultset('ActionLog')->count(), |
275 |
$action_logs + 0, |
276 |
'No log was added' |
277 |
); |
278 |
is( |
279 |
$line_1->accounttype, |
280 |
$Koha::Account::account_type_debit->{'rent'}, |
281 |
'Account type is correctly set' |
282 |
); |
283 |
|
284 |
# Enable logs |
285 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
286 |
|
287 |
my $sip_code = "1"; |
288 |
my $line_2 = $account->add_debit( |
289 |
{ |
290 |
amount => 37, |
291 |
description => 'Rental charge of 37', |
292 |
library_id => $patron->branchcode, |
293 |
note => 'not really important', |
294 |
type => 'rent', |
295 |
user_id => $patron->id, |
296 |
} |
297 |
); |
298 |
|
299 |
is( $account->balance, 62, 'Patron has a balance of 62' ); |
300 |
is( |
301 |
$schema->resultset('ActionLog')->count(), |
302 |
$action_logs + 1, |
303 |
'Log was added' |
304 |
); |
305 |
is( |
306 |
$line_2->accounttype, |
307 |
$Koha::Account::account_type_debit->{'rent'}, |
308 |
'Account type is correctly set' |
309 |
); |
310 |
|
311 |
# offsets have the debit_id set to accountlines_id, and credit_id is undef |
312 |
my $offset_1 = |
313 |
Koha::Account::Offsets->search( { debit_id => $line_1->id } )->next; |
314 |
my $offset_2 = |
315 |
Koha::Account::Offsets->search( { debit_id => $line_2->id } )->next; |
316 |
|
317 |
is( $offset_1->debit_id, $line_1->id, 'debit_id is set for debit 1' ); |
318 |
is( $offset_1->credit_id, undef, 'credit_id is not set for debit 1' ); |
319 |
is( $offset_2->debit_id, $line_2->id, 'debit_id is set for debit 2' ); |
320 |
is( $offset_2->credit_id, undef, 'credit_id is not set for debit 2' ); |
321 |
|
322 |
$schema->storage->txn_rollback; |
323 |
}; |
324 |
|
217 |
subtest 'lines() tests' => sub { |
325 |
subtest 'lines() tests' => sub { |
218 |
|
326 |
|
219 |
plan tests => 1; |
327 |
plan tests => 1; |
220 |
- |
|
|