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 |
- |
|
|