|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 5; |
20 |
use Test::More tests => 7; |
| 21 |
|
21 |
|
| 22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
| 23 |
|
23 |
|
|
Lines 294-299
subtest 'add_credit() tests' => sub {
Link Here
|
| 294 |
$schema->storage->txn_rollback; |
294 |
$schema->storage->txn_rollback; |
| 295 |
}; |
295 |
}; |
| 296 |
|
296 |
|
|
|
297 |
subtest 'get_credit() tests' => sub { |
| 298 |
|
| 299 |
plan tests => 12; |
| 300 |
|
| 301 |
$schema->storage->txn_begin; |
| 302 |
|
| 303 |
my $patron = $builder->build_object( |
| 304 |
{ |
| 305 |
class => 'Koha::Patrons', |
| 306 |
value => { flags => 1 } |
| 307 |
} |
| 308 |
); |
| 309 |
my $userid = $patron->userid; |
| 310 |
my $password = 'thePassword123'; |
| 311 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 312 |
|
| 313 |
my $patron_id = $patron->id; |
| 314 |
my $credit = $patron->account->add_credit( |
| 315 |
{ |
| 316 |
amount => 100, |
| 317 |
description => "A description", |
| 318 |
type => "NEW_CARD", |
| 319 |
interface => 'test', |
| 320 |
} |
| 321 |
); |
| 322 |
my $credit_id = $credit->id; |
| 323 |
|
| 324 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/credits/$credit_id") |
| 325 |
->status_is(200) |
| 326 |
->json_is( '/account_line_id' => $credit_id ) |
| 327 |
->json_is( '/patron_id' => $patron_id ); |
| 328 |
|
| 329 |
$credit->delete(); |
| 330 |
|
| 331 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/credits/$credit_id") |
| 332 |
->status_is(404) |
| 333 |
->json_is( '/error_code' => 'not_found' ) |
| 334 |
->json_is( '/error' => 'Credit not found' ); |
| 335 |
|
| 336 |
my $deleted_patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 337 |
my $deleted_patron_id = $deleted_patron->id; |
| 338 |
$deleted_patron->delete(); |
| 339 |
|
| 340 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$deleted_patron_id/account/credits/$credit_id") |
| 341 |
->status_is(404) |
| 342 |
->json_is( '/error_code' => 'not_found' ) |
| 343 |
->json_is( '/error' => 'Patron not found' ); |
| 344 |
|
| 345 |
$schema->storage->txn_rollback; |
| 346 |
}; |
| 347 |
|
| 297 |
subtest 'list_credits() test' => sub { |
348 |
subtest 'list_credits() test' => sub { |
| 298 |
plan tests => 3; |
349 |
plan tests => 3; |
| 299 |
|
350 |
|
|
Lines 329-334
subtest 'list_credits() test' => sub {
Link Here
|
| 329 |
$schema->storage->txn_rollback; |
380 |
$schema->storage->txn_rollback; |
| 330 |
}; |
381 |
}; |
| 331 |
|
382 |
|
|
|
383 |
subtest 'get_debit() tests' => sub { |
| 384 |
|
| 385 |
plan tests => 12; |
| 386 |
|
| 387 |
$schema->storage->txn_begin; |
| 388 |
|
| 389 |
my $patron = $builder->build_object( |
| 390 |
{ |
| 391 |
class => 'Koha::Patrons', |
| 392 |
value => { flags => 1 } |
| 393 |
} |
| 394 |
); |
| 395 |
my $userid = $patron->userid; |
| 396 |
my $password = 'thePassword123'; |
| 397 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 398 |
|
| 399 |
my $patron_id = $patron->id; |
| 400 |
my $debit = $patron->account->add_debit( |
| 401 |
{ |
| 402 |
amount => 100, |
| 403 |
description => "A description", |
| 404 |
type => "NEW_CARD", |
| 405 |
interface => 'test', |
| 406 |
} |
| 407 |
); |
| 408 |
my $debit_id = $debit->id; |
| 409 |
|
| 410 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/debits/$debit_id") |
| 411 |
->status_is(200) |
| 412 |
->json_is( '/account_line_id' => $debit_id ) |
| 413 |
->json_is( '/patron_id' => $patron_id ); |
| 414 |
|
| 415 |
$debit->delete(); |
| 416 |
|
| 417 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/debits/$debit_id") |
| 418 |
->status_is(404) |
| 419 |
->json_is( '/error_code' => 'not_found' ) |
| 420 |
->json_is( '/error' => 'Debit not found' ); |
| 421 |
|
| 422 |
my $deleted_patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 423 |
my $deleted_patron_id = $deleted_patron->id; |
| 424 |
$deleted_patron->delete(); |
| 425 |
|
| 426 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$deleted_patron_id/account/debits/$debit_id") |
| 427 |
->status_is(404) |
| 428 |
->json_is( '/error_code' => 'not_found' ) |
| 429 |
->json_is( '/error' => 'Patron not found' ); |
| 430 |
|
| 431 |
$schema->storage->txn_rollback; |
| 432 |
}; |
| 332 |
|
433 |
|
| 333 |
subtest 'list_debits() test' => sub { |
434 |
subtest 'list_debits() test' => sub { |
| 334 |
plan tests => 3; |
435 |
plan tests => 3; |
| 335 |
- |
|
|