From 12f7dd454ef4b220da248970a01868d20d8a0eb3 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 28 Jan 2020 16:14:01 -0300 Subject: [PATCH] Bug 24528: Unit tests for Koha::Object->to_api This patch introduces unit tests for the new to_api bejaviour for *_count methods. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => FAIL: Tests fail because the feature is not implemented --- t/db_dependent/Koha/Object.t | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index bcee55ca75..5d94b57799 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -215,7 +215,7 @@ subtest 'TO_JSON tests' => sub { subtest "to_api() tests" => sub { - plan tests => 26; + plan tests => 28; $schema->storage->txn_begin; @@ -330,6 +330,41 @@ subtest "to_api() tests" => sub { "Exception message correct" ); + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + $builder->build_object( + { + class => 'Koha::Holds', + value => { + biblionumber => $biblio->biblionumber, + borrowernumber => $patron->borrowernumber + } + } + ); + $builder->build_object( + { + class => 'Koha::Holds', + value => { + biblionumber => $biblio->biblionumber, + borrowernumber => $patron->borrowernumber + } + } + ); + + my $patron_api = $patron->to_api( + { + embed => { holds_count => { is_count => 1 } } + } + ); + is( $patron_api->{holds_count}, $patron->holds->count, 'Count embeds are supported and work as expected' ); + + throws_ok + { + $patron->to_api({ embed => { holds_count => {} } }); + } + 'Koha::Exceptions::Object::MethodNotCoveredByTests', + 'Unknown method exception thrown if is_count not specified'; + $schema->storage->txn_rollback; }; -- 2.25.0