Bug 29453: (follow-up) Add tests and fix minimum amount in credit.yaml definition

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Agustin Moyano 2023-05-04 14:09:10 +00:00 committed by Tomas Cohen Arazi
parent f4c6a5dfd5
commit 1ecc49dc7a
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 78 additions and 2 deletions

View File

@ -9,7 +9,6 @@ properties:
description: Internal account line identifier
amount:
type: number
minimum: 0
description: Credit amount
amount_outstanding:
type: number

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 2;
use Test::More tests => 4;
use Test::Mojo;
@ -268,3 +268,80 @@ subtest 'add_credit() tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'list_credits() test' => sub {
plan tests => 3;
$schema->storage->txn_begin;
my $patron = $builder->build_object({
class => 'Koha::Patrons',
value => { flags => 1 }
});
my $password = 'thePassword123';
$patron->set_password({ password => $password, skip_validation => 1 });
my $userid = $patron->userid;
my $patron_id = $patron->borrowernumber;
my $account = $patron->account;
$account->add_credit({
type => 'PAYMENT',
amount => 35,
interface => 'staff',
});
$account->add_credit({
type => 'PAYMENT',
amount => 70,
interface => 'staff',
});
my $ret = $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/credits")
->status_is(200)
->tx->res->json;
is(-105, $ret->[0]->{amount} + $ret->[1]->{amount}, 'Total credits are -105');
$schema->storage->txn_rollback;
};
subtest 'list_debits() test' => sub {
plan tests => 3;
$schema->storage->txn_begin;
my $patron = $builder->build_object({
class => 'Koha::Patrons',
value => { flags => 1 }
});
my $password = 'thePassword123';
$patron->set_password({ password => $password, skip_validation => 1 });
my $userid = $patron->userid;
my $patron_id = $patron->borrowernumber;
my $account = $patron->account;
$account->add_debit(
{ amount => 100,
description => "A description",
type => "NEW_CARD",
user_id => $patron->borrowernumber,
interface => 'test',
}
);
$account->add_debit(
{ amount => 40,
description => "A description",
type => "NEW_CARD",
user_id => $patron->borrowernumber,
interface => 'test',
}
);
my $ret = $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/debits")
->status_is(200)
->tx->res->json;
is(140, $ret->[0]->{amount} + $ret->[1]->{amount}, 'Total debits are 140');
$schema->storage->txn_rollback;
};