From 9f98be593a8bfe32ff17adeb9a9c050540b3dc96 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Sat, 28 Oct 2023 09:45:34 -0300 Subject: [PATCH] Bug 29523: Fix tests Some tests compare things to the output of `->to_api` and are exploding because the (now mandatory) `user` parameter is not passed in the call. In the case of IdP.t I just got rid of the use of `to_api` as we are just trying to acknowledge a new user has been created and the API representation of it is irrelevant. Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Auth/Client.t | 5 ++- t/db_dependent/Koha/REST/Plugin/Auth/IdP.t | 2 +- t/db_dependent/api/v1/erm_users.t | 4 +- t/db_dependent/api/v1/ill_requests.t | 45 ++++++++++++---------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/t/db_dependent/Koha/Auth/Client.t b/t/db_dependent/Koha/Auth/Client.t index 7f97e8295c8..149aaa48185 100755 --- a/t/db_dependent/Koha/Auth/Client.t +++ b/t/db_dependent/Koha/Auth/Client.t @@ -69,7 +69,10 @@ subtest 'get_user() tests' => sub { my $data = { id_token => $id_token }; my ( $resolved_patron, $mapped_data, $resolved_domain ) = $client->get_user( { provider => $provider->code, data => $data, interface => 'opac' } ); - is_deeply( $resolved_patron->to_api, $patron->to_api, 'Patron correctly retrieved' ); + is_deeply( + $resolved_patron->to_api( { user => $patron } ), $patron->to_api( { user => $patron } ), + 'Patron correctly retrieved' + ); is( $mapped_data->{firstname}, 'test name', 'Data mapped correctly' ); is( $mapped_data->{surname}, undef, 'No surname mapped' ); is( $domain->identity_provider_domain_id, $resolved_domain->identity_provider_domain_id, 'Is the same domain' ); diff --git a/t/db_dependent/Koha/REST/Plugin/Auth/IdP.t b/t/db_dependent/Koha/REST/Plugin/Auth/IdP.t index d3579cf9c1c..48325367ade 100755 --- a/t/db_dependent/Koha/REST/Plugin/Auth/IdP.t +++ b/t/db_dependent/Koha/REST/Plugin/Auth/IdP.t @@ -40,7 +40,7 @@ post '/register_user' => sub { interface => $params->{interface} } ); - $c->render( status => 200, json => $patron->to_api ); + $c->render( status => 200, json => $patron->unblessed ); } catch { if ( ref($_) eq 'Koha::Exceptions::Auth::Unauthorized' ) { $c->render( status => 401, json => { message => 'unauthorized' } ); diff --git a/t/db_dependent/api/v1/erm_users.t b/t/db_dependent/api/v1/erm_users.t index fff58cbe9dd..379db6562f6 100755 --- a/t/db_dependent/api/v1/erm_users.t +++ b/t/db_dependent/api/v1/erm_users.t @@ -56,7 +56,7 @@ subtest 'list() tests' => sub { # One erm_user created, should get returned $librarian->discard_changes; $t->get_ok("//$userid:$password@/api/v1/erm/users")->status_is(200) - ->json_is( [ $librarian->to_api ] ); + ->json_is( [ $librarian->to_api( { user => $librarian } ) ] ); my $another_erm_user = $builder->build_object( { @@ -67,7 +67,7 @@ subtest 'list() tests' => sub { # Two erm_users created, they should both be returned $t->get_ok("//$userid:$password@/api/v1/erm/users")->status_is(200) - ->json_is( [ $librarian->to_api ] ); + ->json_is( [ $librarian->to_api( { user => $librarian } ) ] ); # Warn on unsupported query parameter $t->get_ok("//$userid:$password@/api/v1/erm/users?blah=blah") diff --git a/t/db_dependent/api/v1/ill_requests.t b/t/db_dependent/api/v1/ill_requests.t index 0769766778d..3e7bb9d681f 100755 --- a/t/db_dependent/api/v1/ill_requests.t +++ b/t/db_dependent/api/v1/ill_requests.t @@ -169,7 +169,7 @@ subtest 'list() tests' => sub { # Three requests exist, expect all three to be returned $t->get_ok("//$userid:$password@/api/v1/ill/requests") ->status_is(200) - ->json_is( [ $req_1->to_api, $req_2->to_api, $ret->to_api ]); + ->json_is( [ $req_1->to_api({user=> $librarian}), $req_2->to_api({user=> $librarian}), $ret->to_api({user=> $librarian}) ]); my $status_query = encode_json({ status => 'REQ' }); my $status_alias_query = encode_json({ status_av => $av_code }); @@ -177,29 +177,34 @@ subtest 'list() tests' => sub { # x-koha-embed: +strings # Two requests exist with status 'REQ', expect them to be returned # One of which also has a status_alias, expect that to be in that request's body - $t->get_ok("//$userid:$password@/api/v1/ill/requests?q=$status_query" => {"x-koha-embed" => "+strings"} ) - ->status_is(200) - ->json_is( [ - { _strings => { status => $response_status }, %{$req_1->to_api} }, - { _strings => { status => $response_status, status_av => $response_status_av }, %{$req_2->to_api} } - ] + $t->get_ok( "//$userid:$password@/api/v1/ill/requests?q=$status_query" => { "x-koha-embed" => "+strings" } ) + ->status_is(200)->json_is( + [ + { _strings => { status => $response_status }, %{ $req_1->to_api( { user => $librarian } ) } }, + { + _strings => { status => $response_status, status_av => $response_status_av }, + %{ $req_2->to_api( { user => $librarian } ) } + } + ] ); # One request with status_alias 'print_copy' exists, expect that to be returned - $t->get_ok("//$userid:$password@/api/v1/ill/requests?q=$status_alias_query" => {"x-koha-embed" => "+strings"} ) - ->status_is(200) - ->json_is( [ - { _strings => { status => $response_status, status_av => $response_status_av }, %{$req_2->to_api} } - ] + $t->get_ok( "//$userid:$password@/api/v1/ill/requests?q=$status_alias_query" => { "x-koha-embed" => "+strings" } ) + ->status_is(200)->json_is( + [ + { + _strings => { status => $response_status, status_av => $response_status_av }, + %{ $req_2->to_api( { user => $librarian } ) } + } + ] ); # x-koha-embed: patron my $patron_query = encode_json({ borrowernumber => $patron->borrowernumber }); # One request related to $patron, make sure it comes back - $t->get_ok("//$userid:$password@/api/v1/ill/requests" => {"x-koha-embed" => "patron"} ) - ->status_is(200) - ->json_has('/0/patron', $patron->to_api); + $t->get_ok( "//$userid:$password@/api/v1/ill/requests" => { "x-koha-embed" => "patron" } )->status_is(200) + ->json_has( '/0/patron', $patron->to_api( { user => $librarian } ) ); # x-koha-embed: comments # Create comment @@ -226,15 +231,13 @@ subtest 'list() tests' => sub { # ILLHiddenRequestStatuses syspref # Hide 'REQ', expect to return just 1 'RET' t::lib::Mocks::mock_preference( 'ILLHiddenRequestStatuses', 'REQ' ); - $t->get_ok( "//$userid:$password@/api/v1/ill/requests" ) - ->status_is(200) - ->json_is( [ $ret->to_api ] ); + $t->get_ok("//$userid:$password@/api/v1/ill/requests")->status_is(200) + ->json_is( [ $ret->to_api( { user => $librarian } ) ] ); # Hide 'RET', expect to return 2 'REQ' t::lib::Mocks::mock_preference( 'ILLHiddenRequestStatuses', 'RET' ); - $t->get_ok( "//$userid:$password@/api/v1/ill/requests?_order_by=staff_notes" ) - ->status_is(200) - ->json_is( [ $req_1->to_api, $req_2->to_api ]); + $t->get_ok("//$userid:$password@/api/v1/ill/requests?_order_by=staff_notes")->status_is(200) + ->json_is( [ $req_1->to_api( { user => $librarian } ), $req_2->to_api( { user => $librarian } ) ] ); # Status code # Warn on unsupported query parameter -- 2.42.0