From 4d36ec21b3efd800f4c7246a9ac40b1f9662a4ff Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 20 Jan 2025 16:46:18 -0300 Subject: [PATCH] Bug 38931: Unit tests Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/api/v1/patrons_accounts.t | 103 ++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/patrons_accounts.t b/t/db_dependent/api/v1/patrons_accounts.t index 31d395ace64..df99f522d25 100755 --- a/t/db_dependent/api/v1/patrons_accounts.t +++ b/t/db_dependent/api/v1/patrons_accounts.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 7; use Test::Mojo; @@ -294,6 +294,57 @@ subtest 'add_credit() tests' => sub { $schema->storage->txn_rollback; }; +subtest 'get_credit() tests' => sub { + + plan tests => 12; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 1 } + } + ); + my $userid = $patron->userid; + my $password = 'thePassword123'; + $patron->set_password( { password => $password, skip_validation => 1 } ); + + my $patron_id = $patron->id; + my $credit = $patron->account->add_credit( + { + amount => 100, + description => "A description", + type => "NEW_CARD", + interface => 'test', + } + ); + my $credit_id = $credit->id; + + $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/credits/$credit_id") + ->status_is(200) + ->json_is( '/account_line_id' => $credit_id ) + ->json_is( '/patron_id' => $patron_id ); + + $credit->delete(); + + $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/credits/$credit_id") + ->status_is(404) + ->json_is( '/error_code' => 'not_found' ) + ->json_is( '/error' => 'Credit not found' ); + + my $deleted_patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $deleted_patron_id = $deleted_patron->id; + $deleted_patron->delete(); + + $t->get_ok("//$userid:$password@/api/v1/patrons/$deleted_patron_id/account/credits/$credit_id") + ->status_is(404) + ->json_is( '/error_code' => 'not_found' ) + ->json_is( '/error' => 'Patron not found' ); + + $schema->storage->txn_rollback; +}; + subtest 'list_credits() test' => sub { plan tests => 3; @@ -329,6 +380,56 @@ subtest 'list_credits() test' => sub { $schema->storage->txn_rollback; }; +subtest 'get_debit() tests' => sub { + + plan tests => 12; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 1 } + } + ); + my $userid = $patron->userid; + my $password = 'thePassword123'; + $patron->set_password( { password => $password, skip_validation => 1 } ); + + my $patron_id = $patron->id; + my $debit = $patron->account->add_debit( + { + amount => 100, + description => "A description", + type => "NEW_CARD", + interface => 'test', + } + ); + my $debit_id = $debit->id; + + $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/debits/$debit_id") + ->status_is(200) + ->json_is( '/account_line_id' => $debit_id ) + ->json_is( '/patron_id' => $patron_id ); + + $debit->delete(); + + $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/debits/$debit_id") + ->status_is(404) + ->json_is( '/error_code' => 'not_found' ) + ->json_is( '/error' => 'Debit not found' ); + + my $deleted_patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $deleted_patron_id = $deleted_patron->id; + $deleted_patron->delete(); + + $t->get_ok("//$userid:$password@/api/v1/patrons/$deleted_patron_id/account/debits/$debit_id") + ->status_is(404) + ->json_is( '/error_code' => 'not_found' ) + ->json_is( '/error' => 'Patron not found' ); + + $schema->storage->txn_rollback; +}; subtest 'list_debits() test' => sub { plan tests => 3; -- 2.48.1