From 6f1358b08dce7c9fff0a56a5503dceb688d219af Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 21 Oct 2019 15:18:32 -0300 Subject: [PATCH] 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 --- t/db_dependent/api/v1/acquisitions_funds.t | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/t/db_dependent/api/v1/acquisitions_funds.t b/t/db_dependent/api/v1/acquisitions_funds.t index 910f6be8ce..307e6d2a1b 100644 --- a/t/db_dependent/api/v1/acquisitions_funds.t +++ b/t/db_dependent/api/v1/acquisitions_funds.t @@ -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; -- 2.23.0