From 0e4b6dcac379a22731ba0ebe08f9c7f020533a62 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 13 Feb 2025 09:58:57 -0300 Subject: [PATCH] Bug 35246: Unit tests --- t/db_dependent/Koha/Biblio.t | 9 ++++++++- t/db_dependent/api/v1/biblios.t | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 9d697b7850e..c1fd10a01e3 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -587,7 +587,7 @@ subtest 'to_api() tests' => sub { my $biblioitem_api = $biblio->biblioitem->to_api; my $biblio_api = $biblio->to_api; - plan tests => ( scalar keys %{$biblioitem_api} ) + 1; + plan tests => ( scalar keys %{$biblioitem_api} ) + 4; foreach my $key ( keys %{$biblioitem_api} ) { is( $biblio_api->{$key}, $biblioitem_api->{$key}, "$key is added to the biblio object" ); @@ -596,6 +596,13 @@ subtest 'to_api() tests' => sub { $biblio_api = $biblio->to_api( { embed => { items => {} } } ); is_deeply( $biblio_api->{items}, [ $item->to_api ], 'Item correctly embedded' ); + $biblio->biblioitem->delete(); + throws_ok { $biblio->to_api } + 'Koha::Exceptions::RelatedObjectNotFound', + 'Exception thrown if the biblioitem accessor returns undef'; + is( $@->class, 'Koha::Biblioitem' ); + is( $@->accessor, 'biblioitem' ); + $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t index f47c5f8bd2f..d0e809dfec5 100755 --- a/t/db_dependent/api/v1/biblios.t +++ b/t/db_dependent/api/v1/biblios.t @@ -50,7 +50,7 @@ my $t = Test::Mojo->new('Koha::REST::V1'); subtest 'get() tests' => sub { - plan tests => 22; + plan tests => 26; $schema->storage->txn_begin; @@ -97,6 +97,13 @@ subtest 'get() tests' => sub { $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) ->status_is(200)->content_is( $biblio->metadata->record->as_formatted ); + # Simulate a data error situation (BZ35246) + $biblio->biblioitem->delete(); + + $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/json' } ) + ->status_is(500)->json_is( '/error_code', 'internal_server_error' ) + ->json_is( '/error', 'Something went wrong, check Koha logs for details.' ); + $biblio->delete; $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } ) ->status_is(404)->json_is( '/error', 'Bibliographic record not found' ); -- 2.48.1