|
Lines 1-91
Link Here
|
| 1 |
#!/usr/bin/env perl |
|
|
| 2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Test::NoWarnings; |
| 21 |
use Test::More tests => 2; |
| 22 |
use Test::Mojo; |
| 23 |
|
| 24 |
use t::lib::TestBuilder; |
| 25 |
use t::lib::Mocks; |
| 26 |
|
| 27 |
use Koha::ERM::Agreements; |
| 28 |
use Koha::ERM::Documents; |
| 29 |
use Koha::ERM::EHoldings::Packages; |
| 30 |
use Koha::ERM::EHoldings::Titles; |
| 31 |
use Koha::ERM::Licenses; |
| 32 |
use Koha::ERM::EUsage::UsageDataProviders; |
| 33 |
|
| 34 |
use Koha::Database; |
| 35 |
|
| 36 |
my $schema = Koha::Database->new->schema; |
| 37 |
my $builder = t::lib::TestBuilder->new; |
| 38 |
|
| 39 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
| 40 |
|
| 41 |
subtest 'count() tests' => sub { |
| 42 |
|
| 43 |
plan tests => 3; |
| 44 |
|
| 45 |
$schema->storage->txn_begin; |
| 46 |
|
| 47 |
Koha::ERM::Agreements->search->delete; |
| 48 |
Koha::ERM::Documents->search->delete; |
| 49 |
Koha::ERM::EHoldings::Packages->search->delete; |
| 50 |
Koha::ERM::EHoldings::Titles->search->delete; |
| 51 |
Koha::ERM::Licenses->search->delete; |
| 52 |
Koha::ERM::EUsage::UsageDataProviders->search->delete; |
| 53 |
|
| 54 |
my $librarian = $builder->build_object( |
| 55 |
{ |
| 56 |
class => 'Koha::Patrons', |
| 57 |
value => { flags => 2**28 } |
| 58 |
} |
| 59 |
); |
| 60 |
|
| 61 |
my $password = 'thePassword123'; |
| 62 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
| 63 |
my $userid = $librarian->userid; |
| 64 |
|
| 65 |
## Authorized user tests |
| 66 |
my $agreement = $builder->build_object( |
| 67 |
{ |
| 68 |
class => 'Koha::ERM::Agreements', |
| 69 |
} |
| 70 |
); |
| 71 |
|
| 72 |
my $license = $builder->build_object( |
| 73 |
{ |
| 74 |
class => 'Koha::ERM::Licenses', |
| 75 |
} |
| 76 |
); |
| 77 |
|
| 78 |
$t->get_ok("//$userid:$password@/api/v1/erm/counts")->status_is(200)->json_is( |
| 79 |
{ |
| 80 |
counts => { |
| 81 |
agreements_count => 1, |
| 82 |
documents_count => 0, |
| 83 |
eholdings_packages_count => 0, |
| 84 |
eholdings_titles_count => 0, |
| 85 |
licenses_count => 1, |
| 86 |
usage_data_providers_count => 0 |
| 87 |
} |
| 88 |
} |
| 89 |
); |
| 90 |
$schema->storage->txn_rollback; |
| 91 |
}; |
| 92 |
- |