Browse Source

Bug 26633: (QA follow-up) Tests on error condition

This patch highlights a problem with the try/catch conditions in the
ad() controlled method. Tests are added, and the controller is fixed to
reflect the right behaviour.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/transfer_limits.t
=> SUCCESS: Tests pass! 409 is returned as appropriate!

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.05.x
Tomás Cohen Arazi 2 years ago
committed by Jonathan Druart
parent
commit
f91ae728bf
  1. 6
      Koha/REST/V1/TransferLimits.pm
  2. 10
      t/db_dependent/api/v1/transfer_limits.t

6
Koha/REST/V1/TransferLimits.pm

@ -72,7 +72,7 @@ sub add {
if ( Koha::Item::Transfer::Limits->search( $transfer_limit->attributes_from_api($params) )->count == 0 ) {
$transfer_limit->store;
} else {
Koha::Exceptions::TransferLimit::Duplicate->throw()
Koha::Exceptions::TransferLimit::Duplicate->throw();
}
return $c->render(
@ -81,10 +81,10 @@ sub add {
);
}
catch {
if ( blessed $_ && $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
if ( blessed $_ && $_->isa('Koha::Exceptions::TransferLimit::Duplicate') ) {
return $c->render(
status => 409,
openapi => { error => $_->error, conflict => $_->duplicate_id }
openapi => { error => "$_" }
);
}

10
t/db_dependent/api/v1/transfer_limits.t

@ -62,7 +62,7 @@ subtest 'list() tests' => sub {
subtest 'add() tests' => sub {
plan tests => 8;
plan tests => 11;
$schema->storage->txn_begin;
@ -109,6 +109,14 @@ subtest 'add() tests' => sub {
->status_is( 201, 'SWAGGER3.2.1' )
->json_has( '' => $limit_hashref, 'SWAGGER3.3.1' );
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits" => json => $limit_hashref )
->status_is( 409, 'Conflict creating the resource' )
->json_is(
{
error => "[A transfer limit with the given parameters already exists!]"
}
);
$schema->storage->txn_rollback;
};

Loading…
Cancel
Save