From 7967f9e578c7d6eec4bea651bd3584e0fa2e8233 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 16 May 2024 08:44:46 -0300 Subject: [PATCH] Bug 28633: Make 'effective_name' embeddable This patch makes the calculated value of `Koha::Patron->effective_name` embeddable in the patrons routes. To test: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/patrons.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- api/v1/swagger/definitions/patron.yaml | 5 +++++ api/v1/swagger/paths/patrons.yaml | 2 ++ t/db_dependent/api/v1/patrons.t | 24 ++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/api/v1/swagger/definitions/patron.yaml b/api/v1/swagger/definitions/patron.yaml index 331989f303f..56e7e21ef08 100644 --- a/api/v1/swagger/definitions/patron.yaml +++ b/api/v1/swagger/definitions/patron.yaml @@ -383,6 +383,11 @@ properties: type: - boolean description: Protected status of the patron + effective_name: + type: + - string + - "null" + description: The effective name to use based on configuration (x-koha-embed) _strings: type: - object diff --git a/api/v1/swagger/paths/patrons.yaml b/api/v1/swagger/paths/patrons.yaml index 8835918ddd4..e8e3bebc394 100644 --- a/api/v1/swagger/paths/patrons.yaml +++ b/api/v1/swagger/paths/patrons.yaml @@ -364,6 +364,7 @@ items: type: string enum: + - effective_name - extended_attributes - checkouts+count - overdues+count @@ -496,6 +497,7 @@ type: string enum: - +strings + - effective_name - extended_attributes collectionFormat: csv produces: diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index 0e3c73e21d9..77d5eca4cbd 100755 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -81,7 +81,7 @@ subtest 'list() tests' => sub { subtest 'librarian access tests' => sub { - plan tests => 21; + plan tests => 22; $schema->storage->txn_begin; @@ -151,6 +151,17 @@ subtest 'list() tests' => sub { { 'x-koha-embed' => 'extended_attributes' } ) ->status_is( 200, "Works, doesn't explode" ); + subtest "embedding 'effective_name'" => sub { + + plan tests => 3; + + $t->get_ok( "//$userid:$password@/api/v1/patrons?" + . 'q={"patron_id":"' + . $patron->id + . '"}' => { 'x-koha-embed' => 'effective_name' } )->status_is(200) + ->json_is( '/0/effective_name' => $patron->effective_name ); + }; + subtest 'searching date and date-time fields' => sub { plan tests => 12; @@ -264,7 +275,8 @@ subtest 'get() tests' => sub { $schema->storage->txn_rollback; subtest 'librarian access tests' => sub { - plan tests => 8; + + plan tests => 9; $schema->storage->txn_begin; @@ -314,6 +326,14 @@ subtest 'get() tests' => sub { ->json_is('/surname' => $patron->surname) ->json_is('/patron_card_lost' => Mojo::JSON->false ); + subtest "embedding 'effective_name'" => sub { + + plan tests => 3; + + $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id => { 'x-koha-embed' => 'effective_name' } ) + ->status_is(200)->json_is( '/effective_name' => $patron->effective_name ); + }; + $schema->storage->txn_rollback; }; -- 2.45.0