Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 2; |
20 |
use Test::More tests => 4; |
21 |
|
21 |
|
22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
23 |
|
23 |
|
Lines 268-270
subtest 'add_credit() tests' => sub {
Link Here
|
268 |
|
268 |
|
269 |
$schema->storage->txn_rollback; |
269 |
$schema->storage->txn_rollback; |
270 |
}; |
270 |
}; |
271 |
- |
271 |
|
|
|
272 |
subtest 'list_credits() test' => sub { |
273 |
plan tests => 3; |
274 |
|
275 |
$schema->storage->txn_begin; |
276 |
|
277 |
my $patron = $builder->build_object({ |
278 |
class => 'Koha::Patrons', |
279 |
value => { flags => 1 } |
280 |
}); |
281 |
my $password = 'thePassword123'; |
282 |
$patron->set_password({ password => $password, skip_validation => 1 }); |
283 |
my $userid = $patron->userid; |
284 |
my $patron_id = $patron->borrowernumber; |
285 |
my $account = $patron->account; |
286 |
|
287 |
$account->add_credit({ |
288 |
type => 'PAYMENT', |
289 |
amount => 35, |
290 |
interface => 'staff', |
291 |
}); |
292 |
$account->add_credit({ |
293 |
type => 'PAYMENT', |
294 |
amount => 70, |
295 |
interface => 'staff', |
296 |
}); |
297 |
|
298 |
my $ret = $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/credits") |
299 |
->status_is(200) |
300 |
->tx->res->json; |
301 |
|
302 |
is(-105, $ret->[0]->{amount} + $ret->[1]->{amount}, 'Total credits are -105'); |
303 |
|
304 |
$schema->storage->txn_rollback; |
305 |
}; |
306 |
|
307 |
|
308 |
subtest 'list_debits() test' => sub { |
309 |
plan tests => 3; |
310 |
|
311 |
$schema->storage->txn_begin; |
312 |
|
313 |
my $patron = $builder->build_object({ |
314 |
class => 'Koha::Patrons', |
315 |
value => { flags => 1 } |
316 |
}); |
317 |
my $password = 'thePassword123'; |
318 |
$patron->set_password({ password => $password, skip_validation => 1 }); |
319 |
my $userid = $patron->userid; |
320 |
my $patron_id = $patron->borrowernumber; |
321 |
my $account = $patron->account; |
322 |
|
323 |
$account->add_debit( |
324 |
{ amount => 100, |
325 |
description => "A description", |
326 |
type => "NEW_CARD", |
327 |
user_id => $patron->borrowernumber, |
328 |
interface => 'test', |
329 |
} |
330 |
); |
331 |
$account->add_debit( |
332 |
{ amount => 40, |
333 |
description => "A description", |
334 |
type => "NEW_CARD", |
335 |
user_id => $patron->borrowernumber, |
336 |
interface => 'test', |
337 |
} |
338 |
); |
339 |
|
340 |
my $ret = $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/debits") |
341 |
->status_is(200) |
342 |
->tx->res->json; |
343 |
|
344 |
is(140, $ret->[0]->{amount} + $ret->[1]->{amount}, 'Total debits are 140'); |
345 |
|
346 |
$schema->storage->txn_rollback; |
347 |
}; |