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

(-)a/t/db_dependent/Koha/Patrons.t (-1 / +33 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 46;
23
use Test::More tests => 47;
24
use Test::Warn;
24
use Test::Warn;
25
use Test::Exception;
25
use Test::Exception;
26
use Test::MockModule;
26
use Test::MockModule;
Lines 3573-3576 subtest 'filter_by_expired_opac_registrations' => sub { Link Here
3573
    $schema->storage->txn_rollback;
3573
    $schema->storage->txn_rollback;
3574
};
3574
};
3575
3575
3576
subtest 'check_for_existing_matches' => sub {
3577
    plan tests => 5;
3578
3579
    $schema->storage->txn_begin;
3580
3581
    my $patron = $builder->build_object(
3582
        { class => 'Koha::Patrons', value => { firstname => 'John', surname => 'Smith', dateofbirth => '1980-01-01' } }
3583
    );
3584
3585
    t::lib::Mocks::mock_preference( 'PatronDuplicateMatchingAddFields', 'dateofbirth|firstname|surname' );
3586
3587
    my $match_result = Koha::Patrons->check_for_existing_matches(
3588
        { firstname => 'John', surname => 'Smith', dateofbirth => '1980-01-01' } );
3589
    is( $match_result->{duplicate_found},                        1,                       'Duplicate found' );
3590
    is( $match_result->{matching_patrons}->next->borrowernumber, $patron->borrowernumber, 'Matching patron' );
3591
3592
    t::lib::Mocks::mock_preference( 'PatronDuplicateMatchingAddFields', 'dateofbirth|firstname|surname|city' );
3593
    $match_result = Koha::Patrons->check_for_existing_matches(
3594
        { firstname => 'John', surname => 'Smith', dateofbirth => '1980-01-01', city => '' } );
3595
    is( $match_result->{duplicate_found}, 1, 'Duplicate found despite missing data for the city field' );
3596
    is(
3597
        $match_result->{matching_patrons}->next->borrowernumber, $patron->borrowernumber,
3598
        'Patron match ignores undefined field and still identifies the match'
3599
    );
3600
3601
    $match_result = Koha::Patrons->check_for_existing_matches(
3602
        { firstname => 'John', surname => 'Smith', dateofbirth => '1980-01-01', city => 'Sandwich, Kent' } );
3603
    is( $match_result->{duplicate_found}, 0, 'No duplicate found' );
3604
3605
    $schema->storage->txn_rollback;
3606
};
3607
3576
$schema->storage->txn_rollback;
3608
$schema->storage->txn_rollback;
(-)a/t/db_dependent/api/v1/patrons.t (-12 / +16 lines)
Lines 427-433 subtest 'add() tests' => sub { Link Here
427
    $schema->storage->txn_rollback;
427
    $schema->storage->txn_rollback;
428
428
429
    subtest 'librarian access tests' => sub {
429
    subtest 'librarian access tests' => sub {
430
        plan tests => 25;
430
        plan tests => 28;
431
431
432
        $schema->storage->txn_begin;
432
        $schema->storage->txn_begin;
433
433
Lines 458-463 subtest 'add() tests' => sub { Link Here
458
        delete $newpatron->{expired};
458
        delete $newpatron->{expired};
459
        delete $newpatron->{anonymized};
459
        delete $newpatron->{anonymized};
460
460
461
        my $password = 'thePassword123';
462
        $librarian->set_password( { password => $password, skip_validation => 1 } );
463
        my $userid = $librarian->userid;
464
        t::lib::Mocks::mock_preference( 'PatronDuplicateMatchingAddFields', 'firstname|surname|dateofbirth' );
465
466
        $t->post_ok( "//$userid:$password@/api/v1/patrons" => json => $newpatron )->status_is(409)
467
            ->json_is( '/error' => "A patron record matching these details already exists" );
468
461
        # Create a library just to make sure its ID doesn't exist on the DB
469
        # Create a library just to make sure its ID doesn't exist on the DB
462
        my $library_to_delete  = $builder->build_object( { class => 'Koha::Libraries' } );
470
        my $library_to_delete  = $builder->build_object( { class => 'Koha::Libraries' } );
463
        my $deleted_library_id = $library_to_delete->id;
471
        my $deleted_library_id = $library_to_delete->id;
Lines 465-478 subtest 'add() tests' => sub { Link Here
465
        # Delete library
473
        # Delete library
466
        $library_to_delete->delete;
474
        $library_to_delete->delete;
467
475
468
        my $password = 'thePassword123';
469
        $librarian->set_password( { password => $password, skip_validation => 1 } );
470
        my $userid = $librarian->userid;
471
472
        $newpatron->{library_id} = $deleted_library_id;
476
        $newpatron->{library_id} = $deleted_library_id;
473
477
474
        $t->post_ok( "//$userid:$password@/api/v1/patrons" => json => $newpatron )->status_is(400)
478
        $t->post_ok( "//$userid:$password@/api/v1/patrons" => { 'x-confirm-not-duplicate' => 1 } => json => $newpatron )
475
            ->json_is( '/error' => "Problem with " . $newpatron->{userid} );
479
            ->status_is(400)->json_is( '/error' => "Problem with " . $newpatron->{userid} );
476
480
477
        $newpatron->{library_id} = $patron->branchcode;
481
        $newpatron->{library_id} = $patron->branchcode;
478
482
Lines 485-492 subtest 'add() tests' => sub { Link Here
485
489
486
        $newpatron->{category_id} = $deleted_category_id;    # Test invalid patron category
490
        $newpatron->{category_id} = $deleted_category_id;    # Test invalid patron category
487
491
488
        $t->post_ok( "//$userid:$password@/api/v1/patrons" => json => $newpatron )->status_is(400)
492
        $t->post_ok( "//$userid:$password@/api/v1/patrons" => { 'x-confirm-not-duplicate' => 1 } => json => $newpatron )
489
            ->json_is( '/error' => "Given category_id does not exist" );
493
            ->status_is(400)->json_is( '/error' => "Given category_id does not exist" );
490
        $newpatron->{category_id} = $patron->categorycode;
494
        $newpatron->{category_id} = $patron->categorycode;
491
495
492
        $newpatron->{falseproperty} = "Non existent property";
496
        $newpatron->{falseproperty} = "Non existent property";
Lines 528-535 subtest 'add() tests' => sub { Link Here
528
532
529
        $newpatron->{userid} = undef;    # force regeneration
533
        $newpatron->{userid} = undef;    # force regeneration
530
        warning_like {
534
        warning_like {
531
            $t->post_ok( "//$userid:$password@/api/v1/patrons" => json => $newpatron )->status_is(409)
535
            $t->post_ok(
532
                ->json_has( '/error', 'Fails when trying to POST duplicate cardnumber' )
536
                "//$userid:$password@/api/v1/patrons" => { 'x-confirm-not-duplicate' => 1 } => json => $newpatron )
537
                ->status_is(409)->json_has( '/error', 'Fails when trying to POST duplicate cardnumber' )
533
                ->json_like( '/conflict' => qr/(borrowers\.)?cardnumber/ );
538
                ->json_like( '/conflict' => qr/(borrowers\.)?cardnumber/ );
534
        }
539
        }
535
        qr/DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key '(borrowers\.)?cardnumber'/;
540
        qr/DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key '(borrowers\.)?cardnumber'/;
536
- 

Return to bug 40082