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