Bugzilla – Attachment 128961 Details for
Bug 28020
Error responses should return a code
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28020: Unit tests
Bug-28020-Unit-tests.patch (text/plain), 3.36 KB, created by
Jonathan Druart
on 2022-01-03 13:39:11 UTC
(
hide
)
Description:
Bug 28020: Unit tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-01-03 13:39:11 UTC
Size:
3.36 KB
patch
obsolete
>From 7147a4d43a3cbd2c34584e7ccc0a14b01c712979 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 27 Dec 2021 08:20:11 -0300 >Subject: [PATCH] Bug 28020: Unit tests > >The unhandled_exception() Mojo helper didn't have proper tests. As this >bug is adding a slight behavior change, I tried to add some. As it >relies on the OpenAPI plugin, it cannot be done the usual way using >Mojo::Lite. So I picked a route and forced an exception through mocking >to be able to write tests. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/api/v1/unhandled_exceptions.t >=> FAIL: The unhandled_exception() helper doesn't return an error_code >in the response payload. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > t/db_dependent/api/v1/unhandled_exceptions.t | 69 ++++++++++++++++++++ > 1 file changed, 69 insertions(+) > create mode 100755 t/db_dependent/api/v1/unhandled_exceptions.t > >diff --git a/t/db_dependent/api/v1/unhandled_exceptions.t b/t/db_dependent/api/v1/unhandled_exceptions.t >new file mode 100755 >index 00000000000..4ebba88b196 >--- /dev/null >+++ b/t/db_dependent/api/v1/unhandled_exceptions.t >@@ -0,0 +1,69 @@ >+#!/usr/bin/env perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Test::MockModule; >+use Test::Mojo; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+use Koha::Database; >+use Koha::Exceptions; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+my $t = Test::Mojo->new('Koha::REST::V1'); >+t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+subtest 'unhandled_exception() tests' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $authorized_patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2**4 } # borrowers flag = 4 >+ } >+ ); >+ my $password = 'thePassword123'; >+ $authorized_patron->set_password( >+ { password => $password, skip_validation => 1 } ); >+ my $userid = $authorized_patron->userid; >+ >+ my $message = 'delete died'; >+ >+ my $mock_patron = Test::MockModule->new('Koha::Patron'); >+ $mock_patron->mock( 'delete', sub { Koha::Exceptions::Exception->throw($message); } ); >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ >+ $t->delete_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id ) >+ ->status_is('500') >+ ->json_is( >+ { error => 'Something went wrong, check Koha logs for details.', >+ error_code => 'internal_server_error', >+ } >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 28020
:
128915
|
128916
|
128917
|
128918
|
128919
|
128920
|
128921
|
128922
|
128923
| 128961 |
128962
|
128963