|
Lines 18-24
Link Here
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::NoWarnings; |
20 |
use Test::NoWarnings; |
| 21 |
use Test::More tests => 6; |
21 |
use Test::More tests => 7; |
| 22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
| 23 |
|
23 |
|
| 24 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
|
Lines 453-455
subtest 'delete() tests' => sub {
Link Here
|
| 453 |
|
453 |
|
| 454 |
$schema->storage->txn_rollback; |
454 |
$schema->storage->txn_rollback; |
| 455 |
}; |
455 |
}; |
| 456 |
- |
456 |
|
|
|
457 |
subtest 'extended_attributes() tests' => sub { |
| 458 |
|
| 459 |
plan tests => 12; |
| 460 |
|
| 461 |
$schema->storage->txn_begin; |
| 462 |
|
| 463 |
my $librarian = $builder->build_object( |
| 464 |
{ |
| 465 |
class => 'Koha::Patrons', |
| 466 |
value => { flags => 2**28 } |
| 467 |
} |
| 468 |
); |
| 469 |
my $password = 'thePassword123'; |
| 470 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
| 471 |
my $userid = $librarian->userid; |
| 472 |
|
| 473 |
# Create an additional field for erm_agreements |
| 474 |
my $additional_field = $builder->build_object( |
| 475 |
{ |
| 476 |
class => 'Koha::AdditionalFields', |
| 477 |
value => { |
| 478 |
tablename => 'erm_agreements', |
| 479 |
name => 'test_field', |
| 480 |
} |
| 481 |
} |
| 482 |
); |
| 483 |
|
| 484 |
# Create an agreement with extended attributes |
| 485 |
my $agreement = $builder->build_object( { class => 'Koha::ERM::Agreements' } ); |
| 486 |
|
| 487 |
$agreement->set_additional_fields( |
| 488 |
[ |
| 489 |
{ |
| 490 |
id => $additional_field->id, |
| 491 |
value => 'test_value', |
| 492 |
} |
| 493 |
] |
| 494 |
); |
| 495 |
|
| 496 |
# Get the agreement with embedded extended_attributes |
| 497 |
my $response = $t->get_ok( "//$userid:$password@/api/v1/erm/agreements/" |
| 498 |
. $agreement->agreement_id => { 'x-koha-embed' => 'extended_attributes' } )->status_is(200)->tx->res->json; |
| 499 |
|
| 500 |
# Verify extended_attributes are present |
| 501 |
ok( exists $response->{extended_attributes}, 'extended_attributes key exists in response' ); |
| 502 |
is( ref $response->{extended_attributes}, 'ARRAY', 'extended_attributes is an array' ); |
| 503 |
is( scalar @{ $response->{extended_attributes} }, 1, 'One extended attribute returned' ); |
| 504 |
|
| 505 |
my $attr = $response->{extended_attributes}[0]; |
| 506 |
is( $attr->{field_id}, $additional_field->id, 'Correct field_id' ); |
| 507 |
is( $attr->{value}, 'test_value', 'Correct value' ); |
| 508 |
ok( !exists $attr->{record_table}, 'record_table field is not exposed in API' ); |
| 509 |
|
| 510 |
# Test with list endpoint |
| 511 |
$response = |
| 512 |
$t->get_ok( "//$userid:$password@/api/v1/erm/agreements" => { 'x-koha-embed' => 'extended_attributes' } ) |
| 513 |
->status_is(200)->tx->res->json; |
| 514 |
|
| 515 |
# Verify record_table is still not present in list endpoint |
| 516 |
my $found = 0; |
| 517 |
foreach my $agr (@$response) { |
| 518 |
if ( $agr->{agreement_id} == $agreement->agreement_id ) { |
| 519 |
$found = 1; |
| 520 |
$attr = $agr->{extended_attributes}[0]; |
| 521 |
ok( !exists $attr->{record_table}, 'record_table field is not exposed in list endpoint' ); |
| 522 |
last; |
| 523 |
} |
| 524 |
} |
| 525 |
ok( $found, 'Agreement found in list response' ); |
| 526 |
|
| 527 |
$schema->storage->txn_rollback; |
| 528 |
}; |