3 # Copyright 2023 PTFS Europe
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Test::More tests => 1;
25 use t::lib::TestBuilder;
28 use JSON qw(encode_json);
30 use Koha::ERM::EUsage::CounterFiles;
33 my $builder = t::lib::TestBuilder->new;
35 my $t = Test::Mojo->new('Koha::REST::V1');
36 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
38 subtest 'get() tests' => sub {
41 my $expected_response = [
44 "address" => "EBSCO Information Services\n10 Estes Street\nIpswich, MA 01938",
45 "address_country" => {
47 "name" => "United States of America"
50 "email" => 'chadmovalli@ebsco.com',
52 "person" => "Chad Movalli",
55 "content_provider_name" => "EBSCO",
58 "name" => "Aggregated_Full_Content"
61 "id" => "b2b2736c-2cb9-48ec-91f4-870336acfb1c",
62 "name" => "EBSCO Information Services",
65 "counter_release" => "5",
66 "report_id" => "TR_J4",
67 "report_name" => "Title Report - Journal Report 4"
70 "counter_release" => "5",
71 "report_id" => "DR_D2",
72 "report_name" => "Database Report - Report 2"
75 "counter_release" => "5",
76 "report_id" => "TR_J3",
77 "report_name" => "Title Report - Journal Report 3"
80 "counter_release" => "5",
81 "report_id" => "DR_D1",
82 "report_name" => "Database Report - Report 1"
85 "counter_release" => "5",
86 "report_id" => "TR_J2",
87 "report_name" => "Title Report - Journal Report 2"
90 "counter_release" => "5",
92 "report_name" => "Platform Master Report"
95 "counter_release" => "5",
96 "report_id" => "TR_B2",
97 "report_name" => "Title Report - Book Report 2"
100 "counter_release" => "5",
101 "report_id" => "TR_B3",
102 "report_name" => "Title Report - Book Report 3"
105 "counter_release" => "5",
107 "report_name" => "Title Master Report"
110 "counter_release" => "5",
111 "report_id" => "TR_B1",
112 "report_name" => "Title Report - Book Report 1"
115 "counter_release" => "5",
116 "report_id" => "PR_P1",
117 "report_name" => "Platform Report - Report 1"
120 "counter_release" => "5",
121 "report_id" => "TR_J1",
122 "report_name" => "Title Report - Journal Report 1"
125 "counter_release" => "5",
127 "report_name" => "Database Master Report"
130 "sushi_services" => [
132 "counter_release" => "5",
133 "url" => "https:\/\/registry.projectcounter.org\/api\/v1\/sushi-service\/b94bc981-fa16-4bf6-ba5f-6c113f7ffa0b\/"
136 "website" => "https:\/\/www.ebsco.com\/"
140 my $librarian = $builder->build_object(
142 class => 'Koha::Patrons',
143 value => { flags => 2**28 }
146 my $password = 'thePassword123';
147 $librarian->set_password( { password => $password, skip_validation => 1 } );
148 my $userid = $librarian->userid;
150 my $patron = $builder->build_object(
152 class => 'Koha::Patrons',
153 value => { flags => 0 }
157 $patron->set_password( { password => $password, skip_validation => 1 } );
158 my $unauth_userid = $patron->userid;
160 # Unauthorized access
161 $t->get_ok("//$unauth_userid:$password@/api/v1/erm/counter_registry")->status_is(403);
163 # Authorised access test
164 my $q = encode_json( { "name" => "EBSCO Information Services" } );
165 my $counter_registry = $t->get_ok("//$userid:$password@/api/v1/erm/counter_registry?q=$q")->status_is(200)->tx->res->json;
166 is_deeply( $counter_registry, $expected_response );