View | Details | Raw Unified | Return to bug 32426
Collapse All | Expand All

(-)a/Koha/REST/V1/Patrons.pm (+12 lines)
Lines 147-152 sub add { Link Here
147
                    openapi => { error => $_->error, conflict => $_->duplicate_id }
147
                    openapi => { error => $_->error, conflict => $_->duplicate_id }
148
                );
148
                );
149
            }
149
            }
150
            elsif ( $_->isa('Koha::Exceptions::Patron::InvalidUserid') ) {
151
                return $c->render(
152
                    status  => 400,
153
                    openapi => { error => "Problem with ". $_->userid }
154
                );
155
            }
150
            elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
156
            elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
151
                return $c->render(
157
                return $c->render(
152
                    status  => 400,
158
                    status  => 400,
Lines 282-287 sub update { Link Here
282
                openapi => { error => $_->error, conflict => $_->duplicate_id }
288
                openapi => { error => $_->error, conflict => $_->duplicate_id }
283
            );
289
            );
284
        }
290
        }
291
        elsif ( $_->isa('Koha::Exceptions::Patron::InvalidUserid') ) {
292
            return $c->render(
293
                status  => 400,
294
                openapi => { error => "Problem with ". $_->userid }
295
            );
296
        }
285
        elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
297
        elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
286
            return $c->render(
298
            return $c->render(
287
                status  => 400,
299
                status  => 400,
(-)a/t/db_dependent/api/v1/patrons.t (-14 / +9 lines)
Lines 302-308 subtest 'add() tests' => sub { Link Here
302
    $schema->storage->txn_rollback;
302
    $schema->storage->txn_rollback;
303
303
304
    subtest 'librarian access tests' => sub {
304
    subtest 'librarian access tests' => sub {
305
        plan tests => 25;
305
        plan tests => 24;
306
306
307
        $schema->storage->txn_begin;
307
        $schema->storage->txn_begin;
308
308
Lines 364-374 subtest 'add() tests' => sub { Link Here
364
364
365
        $newpatron->{library_id} = $deleted_library_id;
365
        $newpatron->{library_id} = $deleted_library_id;
366
366
367
        warning_like {
367
        $t->post_ok("//$userid:$password@/api/v1/patrons" => json => $newpatron)
368
            $t->post_ok("//$userid:$password@/api/v1/patrons" => json => $newpatron)
368
          ->status_is(400)
369
              ->status_is(409)
369
          ->json_is('/error' => "Problem with ". $newpatron->{userid} );
370
              ->json_is('/error' => "Duplicate ID"); }
371
            qr/DBD::mysql::st execute failed: Duplicate entry/;
372
370
373
        $newpatron->{library_id} = $patron->branchcode;
371
        $newpatron->{library_id} = $patron->branchcode;
374
372
Lines 418-423 subtest 'add() tests' => sub { Link Here
418
          ->json_is( '/date_of_birth' => $newpatron->{ date_of_birth }, 'Date field set (Bug 28585)' )
416
          ->json_is( '/date_of_birth' => $newpatron->{ date_of_birth }, 'Date field set (Bug 28585)' )
419
          ->json_is( '/last_seen'     => $newpatron->{ last_seen }, 'Date-time field set (Bug 28585)' );
417
          ->json_is( '/last_seen'     => $newpatron->{ last_seen }, 'Date-time field set (Bug 28585)' );
420
418
419
        $newpatron->{userid} = undef; # force regeneration
421
        warning_like {
420
        warning_like {
422
            $t->post_ok("//$userid:$password@/api/v1/patrons" => json => $newpatron)
421
            $t->post_ok("//$userid:$password@/api/v1/patrons" => json => $newpatron)
423
              ->status_is(409)
422
              ->status_is(409)
Lines 592-598 subtest 'update() tests' => sub { Link Here
592
    $schema->storage->txn_rollback;
591
    $schema->storage->txn_rollback;
593
592
594
    subtest 'librarian access tests' => sub {
593
    subtest 'librarian access tests' => sub {
595
        plan tests => 45;
594
        plan tests => 43;
596
595
597
        $schema->storage->txn_begin;
596
        $schema->storage->txn_begin;
598
597
Lines 677-688 subtest 'update() tests' => sub { Link Here
677
        $newpatron->{cardnumber} = $patron_1->cardnumber;
676
        $newpatron->{cardnumber} = $patron_1->cardnumber;
678
        $newpatron->{userid}     = $patron_1->userid;
677
        $newpatron->{userid}     = $patron_1->userid;
679
678
680
        warning_like {
679
        $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron )
681
            $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $patron_2->borrowernumber => json => $newpatron )
680
          ->status_is(400)
682
              ->status_is(409)
681
          ->json_has( '/error', "Problem with userid ". $patron_1->userid );
683
              ->json_has( '/error', "Fails when trying to update to an existing cardnumber or userid")
684
              ->json_like( '/conflict' => qr/(borrowers\.)?cardnumber/ ); }
685
            qr/DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key '(borrowers\.)?cardnumber'/;
686
682
687
        $newpatron->{ cardnumber } = $patron_1->id . $patron_2->id;
683
        $newpatron->{ cardnumber } = $patron_1->id . $patron_2->id;
688
        $newpatron->{ userid }     = "user" . $patron_1->id.$patron_2->id;
684
        $newpatron->{ userid }     = "user" . $patron_1->id.$patron_2->id;
689
- 

Return to bug 32426