Bug 32426: (follow-up) Fix api/v1/patrons.t

We use another exception now.

Test plan:
Run t/db_dependent/api/v1/patrons.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Marcel de Rooy 2023-03-28 06:41:59 +00:00 committed by Tomas Cohen Arazi
parent 0d3e26d32c
commit e96f32b29c
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 21 additions and 13 deletions

View file

@ -147,6 +147,12 @@ sub add {
openapi => { error => $_->error, conflict => $_->duplicate_id }
);
}
elsif ( $_->isa('Koha::Exceptions::Patron::InvalidUserid') ) {
return $c->render(
status => 400,
openapi => { error => "Problem with ". $_->userid }
);
}
elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
return $c->render(
status => 400,
@ -282,6 +288,12 @@ sub update {
openapi => { error => $_->error, conflict => $_->duplicate_id }
);
}
elsif ( $_->isa('Koha::Exceptions::Patron::InvalidUserid') ) {
return $c->render(
status => 400,
openapi => { error => "Problem with ". $_->userid }
);
}
elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
return $c->render(
status => 400,

View file

@ -302,7 +302,7 @@ subtest 'add() tests' => sub {
$schema->storage->txn_rollback;
subtest 'librarian access tests' => sub {
plan tests => 25;
plan tests => 24;
$schema->storage->txn_begin;
@ -364,11 +364,9 @@ subtest 'add() tests' => sub {
$newpatron->{library_id} = $deleted_library_id;
warning_like {
$t->post_ok("//$userid:$password@/api/v1/patrons" => json => $newpatron)
->status_is(409)
->json_is('/error' => "Duplicate ID"); }
qr/DBD::mysql::st execute failed: Duplicate entry/;
$t->post_ok("//$userid:$password@/api/v1/patrons" => json => $newpatron)
->status_is(400)
->json_is('/error' => "Problem with ". $newpatron->{userid} );
$newpatron->{library_id} = $patron->branchcode;
@ -418,6 +416,7 @@ subtest 'add() tests' => sub {
->json_is( '/date_of_birth' => $newpatron->{ date_of_birth }, 'Date field set (Bug 28585)' )
->json_is( '/last_seen' => $newpatron->{ last_seen }, 'Date-time field set (Bug 28585)' );
$newpatron->{userid} = undef; # force regeneration
warning_like {
$t->post_ok("//$userid:$password@/api/v1/patrons" => json => $newpatron)
->status_is(409)
@ -592,7 +591,7 @@ subtest 'update() tests' => sub {
$schema->storage->txn_rollback;
subtest 'librarian access tests' => sub {
plan tests => 45;
plan tests => 43;
$schema->storage->txn_begin;
@ -677,12 +676,9 @@ subtest 'update() tests' => sub {
$newpatron->{cardnumber} = $patron_1->cardnumber;
$newpatron->{userid} = $patron_1->userid;
warning_like {
$t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron )
->status_is(409)
->json_has( '/error', "Fails when trying to update to an existing cardnumber or userid")
->json_like( '/conflict' => qr/(borrowers\.)?cardnumber/ ); }
qr/DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key '(borrowers\.)?cardnumber'/;
$t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron )
->status_is(400)
->json_has( '/error', "Problem with userid ". $patron_1->userid );
$newpatron->{ cardnumber } = $patron_1->id . $patron_2->id;
$newpatron->{ userid } = "user" . $patron_1->id.$patron_2->id;