From 636e1cd07b40284106ab94c552fa597abc179946 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 17 Oct 2025 09:28:39 +0000 Subject: [PATCH] Bug 39320: (QA follow-up): Add counts API tests prove t/db_dependent/api/v1/erm_counts.t --- t/db_dependent/api/v1/erm_counts.t | 73 ++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 t/db_dependent/api/v1/erm_counts.t diff --git a/t/db_dependent/api/v1/erm_counts.t b/t/db_dependent/api/v1/erm_counts.t new file mode 100755 index 00000000000..920242920a4 --- /dev/null +++ b/t/db_dependent/api/v1/erm_counts.t @@ -0,0 +1,73 @@ +#!/usr/bin/env perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::NoWarnings; +use Test::More tests => 2; +use Test::Mojo; + +use t::lib::TestBuilder; +use t::lib::Mocks; + +use Koha::Database; + +my $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; + +my $t = Test::Mojo->new('Koha::REST::V1'); + +subtest 'count() tests' => sub { + + plan tests => 3; + + $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; + + ## Authorized user tests + my $agreement = $builder->build_object( + { + class => 'Koha::ERM::Agreements', + } + ); + + my $license = $builder->build_object( + { + class => 'Koha::ERM::Licenses', + } + ); + + $t->get_ok("//$userid:$password@/api/v1/erm/counts")->status_is(200)->json_is( + { + counts => { + agreements_count => 1, documents_count => 0, eholdings_packages_count => 0, + eholdings_titles_count => 0, licenses_count => 1, usage_data_providers_count => 0 + } + } + ); + $schema->storage->txn_rollback; +}; -- 2.39.5