Bugzilla – Attachment 190892 Details for
Bug 41520
Using additional fields on ERM agreements results in an error when loading the agreements table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41520: Add tests for extended_attributes in ERM agreements API
bf18706.patch (text/plain), 3.86 KB, created by
Martin Renvoize (ashimema)
on 2026-01-05 15:06:48 UTC
(
hide
)
Description:
Bug 41520: Add tests for extended_attributes in ERM agreements API
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2026-01-05 15:06:48 UTC
Size:
3.86 KB
patch
obsolete
>From bf18706f30258be8d546d736c331f84f5f07c1b9 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Mon, 5 Jan 2026 15:03:01 +0000 >Subject: [PATCH] Bug 41520: Add tests for extended_attributes in ERM > agreements API > >This patch adds api unit tests for the extended_attributes functionality in the >ERM agreements API to ensure that: > >1. Extended attributes are correctly returned when embedded >2. The internal record_table field is not exposed via the API >3. Both single GET and list endpoints work correctly with extended_attributes > >Test plan: >1. prove t/db_dependent/api/v1/erm_agreements.t >2. Verify all tests pass >--- > t/db_dependent/api/v1/erm_agreements.t | 75 +++++++++++++++++++++++++- > 1 file changed, 74 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/api/v1/erm_agreements.t b/t/db_dependent/api/v1/erm_agreements.t >index 5846b57473a..83236237548 100755 >--- a/t/db_dependent/api/v1/erm_agreements.t >+++ b/t/db_dependent/api/v1/erm_agreements.t >@@ -18,7 +18,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 6; >+use Test::More tests => 7; > use Test::Mojo; > > use t::lib::TestBuilder; >@@ -453,3 +453,76 @@ subtest 'delete() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'extended_attributes() tests' => sub { >+ >+ plan tests => 12; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2**28 } >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ # Create an additional field for erm_agreements >+ my $additional_field = $builder->build_object( >+ { >+ class => 'Koha::AdditionalFields', >+ value => { >+ tablename => 'erm_agreements', >+ name => 'test_field', >+ } >+ } >+ ); >+ >+ # Create an agreement with extended attributes >+ my $agreement = $builder->build_object( { class => 'Koha::ERM::Agreements' } ); >+ >+ $agreement->set_additional_fields( >+ [ >+ { >+ id => $additional_field->id, >+ value => 'test_value', >+ } >+ ] >+ ); >+ >+ # Get the agreement with embedded extended_attributes >+ my $response = $t->get_ok( "//$userid:$password@/api/v1/erm/agreements/" >+ . $agreement->agreement_id => { 'x-koha-embed' => 'extended_attributes' } )->status_is(200)->tx->res->json; >+ >+ # Verify extended_attributes are present >+ ok( exists $response->{extended_attributes}, 'extended_attributes key exists in response' ); >+ is( ref $response->{extended_attributes}, 'ARRAY', 'extended_attributes is an array' ); >+ is( scalar @{ $response->{extended_attributes} }, 1, 'One extended attribute returned' ); >+ >+ my $attr = $response->{extended_attributes}[0]; >+ is( $attr->{field_id}, $additional_field->id, 'Correct field_id' ); >+ is( $attr->{value}, 'test_value', 'Correct value' ); >+ ok( !exists $attr->{record_table}, 'record_table field is not exposed in API' ); >+ >+ # Test with list endpoint >+ $response = >+ $t->get_ok( "//$userid:$password@/api/v1/erm/agreements" => { 'x-koha-embed' => 'extended_attributes' } ) >+ ->status_is(200)->tx->res->json; >+ >+ # Verify record_table is still not present in list endpoint >+ my $found = 0; >+ foreach my $agr (@$response) { >+ if ( $agr->{agreement_id} == $agreement->agreement_id ) { >+ $found = 1; >+ $attr = $agr->{extended_attributes}[0]; >+ ok( !exists $attr->{record_table}, 'record_table field is not exposed in list endpoint' ); >+ last; >+ } >+ } >+ ok( $found, 'Agreement found in list response' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.52.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41520
:
190892
|
190893
|
190906
|
190907
|
190915
|
190916
|
190927
|
190928