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