Bug 23843: Make funds endpoint tests more robust

Now that we use ->to_api all the object attributes are returned, so the
original tests that didn't follow the FKs would pass, and now they
don't. If there is no budget linked to the fund, it will return undef,
which is not accepted on the API (though it accepts not returning the
attribute).

To test:
1. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/acquisitions_funds.t
=> SUCCESS: Tests pass!

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomas Cohen Arazi 2019-10-21 15:18:32 -03:00 committed by Martin Renvoize
parent 99a1a6db0f
commit ecf030b798
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 16 additions and 12 deletions

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 14;
use Test::More tests => 13;
use Test::Mojo;
use t::lib::TestBuilder;
use t::lib::Mocks;
@ -51,14 +51,18 @@ my $unauth_password = 'thePassword123';
$patron->set_password({ password => $unauth_password, skip_validation => 1 });
my $unauth_userid = $patron->userid;
my $fund1 = {
budget_code => 'ABCD',
budget_amount => '123.132000',
budget_name => 'Periodiques',
budget_notes => 'This is a note',
};
my $budget_id = AddBudget($fund1);
isnt( $budget_id, undef, 'AddBudget does not returns undef' );
my $fund_name = 'Periodiques';
my $fund = $builder->build_object(
{
class => 'Koha::Acquisition::Funds',
value => {
budget_amount => '123.132000',
budget_name => $fund_name,
budget_notes => 'This is a note'
}
}
);
$t->get_ok('/api/v1/acquisitions/funds')
->status_is(401);
@ -69,15 +73,15 @@ $t->get_ok('/api/v1/acquisitions/funds/?name=testFund')
$t->get_ok("//$unauth_userid:$unauth_password@/api/v1/acquisitions/funds")
->status_is(403);
$t->get_ok("//$unauth_userid:$unauth_password@/api/v1/acquisitions/funds/?name=" . $fund1->{ budget_name })
$t->get_ok("//$unauth_userid:$unauth_password@/api/v1/acquisitions/funds?name=" . $fund_name)
->status_is(403);
$t->get_ok("//$userid:$password@/api/v1/acquisitions/funds")
->status_is(200);
$t->get_ok("//$userid:$password@/api/v1/acquisitions/funds/?name=" . $fund1->{ budget_name })
$t->get_ok("//$userid:$password@/api/v1/acquisitions/funds?name=" . $fund_name)
->status_is(200)
->json_like('/0/name' => qr/$fund1->{ budget_name }/);
->json_like('/0/name' => qr/$fund_name/);
$schema->storage->txn_rollback;