Lines 35-40
use Koha::Exceptions::Patron::Attribute;
Link Here
|
35 |
use Koha::Old::Patrons; |
35 |
use Koha::Old::Patrons; |
36 |
use Koha::Patron::Attributes; |
36 |
use Koha::Patron::Attributes; |
37 |
use Koha::Patron::Debarments qw( AddDebarment ); |
37 |
use Koha::Patron::Debarments qw( AddDebarment ); |
|
|
38 |
use Koha::Notice::Messages; |
38 |
|
39 |
|
39 |
use JSON qw(encode_json); |
40 |
use JSON qw(encode_json); |
40 |
|
41 |
|
Lines 302-308
subtest 'add() tests' => sub {
Link Here
|
302 |
$schema->storage->txn_rollback; |
303 |
$schema->storage->txn_rollback; |
303 |
|
304 |
|
304 |
subtest 'librarian access tests' => sub { |
305 |
subtest 'librarian access tests' => sub { |
305 |
plan tests => 24; |
306 |
plan tests => 25; |
306 |
|
307 |
|
307 |
$schema->storage->txn_begin; |
308 |
$schema->storage->txn_begin; |
308 |
|
309 |
|
Lines 316-343
subtest 'add() tests' => sub {
Link Here
|
316 |
|
317 |
|
317 |
# Mock early, so existing mandatory attributes don't break all the tests |
318 |
# Mock early, so existing mandatory attributes don't break all the tests |
318 |
my $mocked_patron = Test::MockModule->new('Koha::Patron'); |
319 |
my $mocked_patron = Test::MockModule->new('Koha::Patron'); |
319 |
$mocked_patron->mock( |
|
|
320 |
'extended_attributes', |
321 |
sub { |
322 |
|
323 |
if ($extended_attrs_exception) { |
324 |
if ( $extended_attrs_exception eq 'Koha::Exceptions::Patron::Attribute::NonRepeatable' |
325 |
or $extended_attrs_exception eq 'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint' |
326 |
) |
327 |
{ |
328 |
$extended_attrs_exception->throw( |
329 |
attribute => Koha::Patron::Attribute->new( |
330 |
{ code => $code, attribute => $attr } |
331 |
) |
332 |
); |
333 |
} |
334 |
else { |
335 |
$extended_attrs_exception->throw( type => $type ); |
336 |
} |
337 |
} |
338 |
return []; |
339 |
} |
340 |
); |
341 |
|
320 |
|
342 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
321 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
343 |
my $newpatron = $patron->to_api; |
322 |
my $newpatron = $patron->to_api; |
Lines 403-420
subtest 'add() tests' => sub {
Link Here
|
403 |
# Set a date-time field |
382 |
# Set a date-time field |
404 |
$newpatron->{last_seen} = output_pref({ dt => dt_from_string->add( days => -1 ), dateformat => 'rfc3339' }); |
383 |
$newpatron->{last_seen} = output_pref({ dt => dt_from_string->add( days => -1 ), dateformat => 'rfc3339' }); |
405 |
|
384 |
|
406 |
$t->post_ok("//$userid:$password@/api/v1/patrons" => json => $newpatron) |
385 |
$t->post_ok("//$userid:$password@/api/v1/patrons" => { 'x-koha-welcome' => 'email' } => json => $newpatron) |
407 |
->status_is(201, 'Patron created successfully') |
386 |
->status_is(201, 'Patron created successfully') |
408 |
->header_like( |
387 |
->header_like( |
409 |
Location => qr|^\/api\/v1\/patrons/\d*|, |
388 |
Location => qr|^\/api\/v1\/patrons/\d*|, |
410 |
'SWAGGER3.4.1' |
389 |
'SWAGGER3.4.1' |
411 |
) |
390 |
) |
412 |
->json_has('/patron_id', 'got a patron_id') |
391 |
->json_has('/patron_id', 'got a patron_id') |
413 |
->json_is( '/cardnumber' => $newpatron->{ cardnumber }) |
392 |
->json_is( '/cardnumber' => $newpatron->{cardnumber}) |
414 |
->json_is( '/surname' => $newpatron->{ surname }) |
393 |
->json_is( '/surname' => $newpatron->{surname}) |
415 |
->json_is( '/firstname' => $newpatron->{ firstname }) |
394 |
->json_is( '/firstname' => $newpatron->{firstname}) |
416 |
->json_is( '/date_of_birth' => $newpatron->{ date_of_birth }, 'Date field set (Bug 28585)' ) |
395 |
->json_is( '/date_of_birth' => $newpatron->{date_of_birth}, 'Date field set (Bug 28585)' ) |
417 |
->json_is( '/last_seen' => $newpatron->{ last_seen }, 'Date-time field set (Bug 28585)' ); |
396 |
->json_is( '/last_seen' => $newpatron->{last_seen}, 'Date-time field set (Bug 28585)' ); |
|
|
397 |
|
398 |
my $p = Koha::Patrons->find( { cardnumber => $newpatron->{cardnumber} } ); |
399 |
is( Koha::Notice::Messages->search({ borrowernumber => $p->borrowernumber })->count, 1 , "Patron got welcome notice" ); |
418 |
|
400 |
|
419 |
$newpatron->{userid} = undef; # force regeneration |
401 |
$newpatron->{userid} = undef; # force regeneration |
420 |
warning_like { |
402 |
warning_like { |
Lines 428-433
subtest 'add() tests' => sub {
Link Here
|
428 |
|
410 |
|
429 |
plan tests => 19; |
411 |
plan tests => 19; |
430 |
|
412 |
|
|
|
413 |
$mocked_patron->mock( |
414 |
'extended_attributes', |
415 |
sub { |
416 |
|
417 |
if ($extended_attrs_exception) { |
418 |
if ( $extended_attrs_exception eq 'Koha::Exceptions::Patron::Attribute::NonRepeatable' |
419 |
or $extended_attrs_exception eq 'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint' |
420 |
) |
421 |
{ |
422 |
$extended_attrs_exception->throw( |
423 |
attribute => Koha::Patron::Attribute->new( |
424 |
{ code => $code, attribute => $attr } |
425 |
) |
426 |
); |
427 |
} |
428 |
else { |
429 |
$extended_attrs_exception->throw( type => $type ); |
430 |
} |
431 |
} |
432 |
return []; |
433 |
} |
434 |
); |
435 |
|
431 |
my $patrons_count = Koha::Patrons->search->count; |
436 |
my $patrons_count = Koha::Patrons->search->count; |
432 |
|
437 |
|
433 |
$extended_attrs_exception = 'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute'; |
438 |
$extended_attrs_exception = 'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute'; |
434 |
- |
|
|