Bugzilla – Attachment 158527 Details for
Bug 35218
No tests for /erm/sushi_service
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35218: Add unit tests for the counter registry API
Bug-35218-Add-unit-tests-for-the-counter-registry-.patch (text/plain), 12.34 KB, created by
Matt Blenkinsop
on 2023-11-06 14:17:31 UTC
(
hide
)
Description:
Bug 35218: Add unit tests for the counter registry API
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2023-11-06 14:17:31 UTC
Size:
12.34 KB
patch
obsolete
>From 7d7b26fa5b1a575af92e979a1506fb15800366cb Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Date: Mon, 6 Nov 2023 14:14:45 +0000 >Subject: [PATCH] Bug 35218: Add unit tests for the counter registry API > >This patch adds two unit tests to cover the integration with the Counter Registry API in the Usage Statistics module. This is to prevent regressions caused either by changes to the Koha endpoint, or by changes to the Counter Registry API that might require changes in Koha to handle. > >Test plan: >1) prove t/db_dependent/api/v1/erm_counter_registries.t >2) prove t/db_dependent/api/v1/erm_sushi_services.t >--- > .../UsageStatisticsDataProvidersFormAdd.vue | 8 +- > .../api/v1/erm_counter_registries.t | 167 ++++++++++++++++++ > t/db_dependent/api/v1/erm_sushi_services.t | 104 +++++++++++ > 3 files changed, 273 insertions(+), 6 deletions(-) > create mode 100644 t/db_dependent/api/v1/erm_counter_registries.t > create mode 100644 t/db_dependent/api/v1/erm_sushi_services.t > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersFormAdd.vue >index 8dd5de4523..defdcabe2a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersFormAdd.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersFormAdd.vue >@@ -47,11 +47,7 @@ > >{{ $__("Searching...") }} > </template> > <template v-else v-slot:no-options >- >{{ >- $__( >- "Type at least two characters to search" >- ) >- }} >+ >{{ $__("No results found") }} > </template> > <template #search="{ attributes, events }"> > <input >@@ -505,7 +501,7 @@ export default { > api_key_required && this.required_fields.push("API") > requestor_id_required && > this.required_fields.push("Requestor") >- this.sushi_service = sushi_service >+ this.sushi_service = sushi_service || {} > }, > error => {} > ) >diff --git a/t/db_dependent/api/v1/erm_counter_registries.t b/t/db_dependent/api/v1/erm_counter_registries.t >new file mode 100644 >index 0000000000..11d91146c3 >--- /dev/null >+++ b/t/db_dependent/api/v1/erm_counter_registries.t >@@ -0,0 +1,167 @@ >+#!/usr/bin/env perl >+ >+# Copyright 2023 PTFS Europe >+ >+# 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 <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Test::Mojo; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use JSON qw(encode_json); >+ >+use Koha::ERM::EUsage::CounterFiles; >+use Koha::Database; >+ >+my $builder = t::lib::TestBuilder->new; >+ >+my $t = Test::Mojo->new('Koha::REST::V1'); >+t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+subtest 'get() tests' => sub { >+ plan tests => 5; >+ >+ my $expected_response = [ >+ { >+ "abbrev" => "EBSCO", >+ "address" => "EBSCO Information Services\n10 Estes Street\nIpswich, MA 01938", >+ "address_country" => { >+ "code" => "US", >+ "name" => "United States of America" >+ }, >+ "contact" => { >+ "email" => 'chadmovalli@ebsco.com', >+ "form_url" => "", >+ "person" => "Chad Movalli", >+ "phone" => "" >+ }, >+ "content_provider_name" => "EBSCO", >+ "host_types" => [ >+ { >+ "name" => "Aggregated_Full_Content" >+ } >+ ], >+ "id" => "b2b2736c-2cb9-48ec-91f4-870336acfb1c", >+ "name" => "EBSCO Information Services", >+ "reports" => [ >+ { >+ "counter_release" => "5", >+ "report_id" => "TR_J4", >+ "report_name" => "Title Report - Journal Report 4" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "DR_D2", >+ "report_name" => "Database Report - Report 2" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "TR_J3", >+ "report_name" => "Title Report - Journal Report 3" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "DR_D1", >+ "report_name" => "Database Report - Report 1" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "TR_J2", >+ "report_name" => "Title Report - Journal Report 2" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "PR", >+ "report_name" => "Platform Master Report" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "TR_B2", >+ "report_name" => "Title Report - Book Report 2" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "TR_B3", >+ "report_name" => "Title Report - Book Report 3" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "TR", >+ "report_name" => "Title Master Report" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "TR_B1", >+ "report_name" => "Title Report - Book Report 1" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "PR_P1", >+ "report_name" => "Platform Report - Report 1" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "TR_J1", >+ "report_name" => "Title Report - Journal Report 1" >+ }, >+ { >+ "counter_release" => "5", >+ "report_id" => "DR", >+ "report_name" => "Database Master Report" >+ } >+ ], >+ "sushi_services" => [ >+ { >+ "counter_release" => "5", >+ "url" => "https:\/\/registry.projectcounter.org\/api\/v1\/sushi-service\/b94bc981-fa16-4bf6-ba5f-6c113f7ffa0b\/" >+ } >+ ], >+ "website" => "https:\/\/www.ebsco.com\/" >+ } >+ ]; >+ >+ 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; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ # Unauthorized access >+ $t->get_ok("//$unauth_userid:$password@/api/v1/erm/counter_registry")->status_is(403); >+ >+ # Authorised access test >+ my $q = encode_json( { "name" => "EBSCO Information Services" } ); >+ my $counter_registry = $t->get_ok("//$userid:$password@/api/v1/erm/counter_registry?q=$q")->status_is(200)->tx->res->json; >+ is_deeply( $counter_registry, $expected_response ); >+}; >diff --git a/t/db_dependent/api/v1/erm_sushi_services.t b/t/db_dependent/api/v1/erm_sushi_services.t >new file mode 100644 >index 0000000000..7ae2e5c578 >--- /dev/null >+++ b/t/db_dependent/api/v1/erm_sushi_services.t >@@ -0,0 +1,104 @@ >+#!/usr/bin/env perl >+ >+# Copyright 2023 PTFS Europe >+ >+# 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 <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Test::Mojo; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use JSON qw(encode_json); >+ >+use Koha::ERM::EUsage::CounterFiles; >+use Koha::Database; >+ >+my $builder = t::lib::TestBuilder->new; >+ >+my $t = Test::Mojo->new('Koha::REST::V1'); >+t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+subtest 'get() tests' => sub { >+ plan tests => 5; >+ >+ my $service_url = "https://registry.projectcounter.org/api/v1/sushi-service/b94bc981-fa16-4bf6-ba5f-6c113f7ffa0b/"; >+ my $expected_response = { >+ "api_key_info"=> "", >+ "api_key_required"=> 0, >+ "contact"=> { >+ "email"=> 'chadmovalli@ebsco.com', >+ "form_url"=> "", >+ "person"=> "Chad Movalli", >+ "phone"=> "" >+ }, >+ "counter_release"=> "5", >+ "credentials_auto_expire"=> 0, >+ "credentials_auto_expire_info"=> "", >+ "customer_id_info"=> "This is your EBSCOhost Customer ID", >+ "customizations_in_place"=> 0, >+ "customizations_info"=> "", >+ "data_host"=> "https:\/\/registry.projectcounter.org\/api\/v1\/usage-data-host\/72a35413-6fcd-44f2-8bce-0c7b2373e33f\/", >+ "id"=> "b94bc981-fa16-4bf6-ba5f-6c113f7ffa0b", >+ "ip_address_authorization"=> 0, >+ "ip_address_authorization_info"=> "", >+ "notification_count"=> 1, >+ "notifications_url"=> "https:\/\/registry.projectcounter.org\/api\/v1\/sushi-service\/b94bc981-fa16-4bf6-ba5f-6c113f7ffa0b\/notification\/", >+ "platform_attr_required"=> 0, >+ "platform_specific_info"=> "", >+ "request_volume_limits_applied"=> 0, >+ "request_volume_limits_info"=> "", >+ "requestor_id_info"=> "Customers generate their Requestor ID in EBSCOAdmin on the SUSHI Authentication tab within the COUNTER R5 Reports section.", >+ "requestor_id_required"=> 1, >+ "url"=> "https:\/\/sushi.ebscohost.com\/R5" >+ }; >+ >+ 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; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ # Unauthorized access >+ $t->get_ok("//$unauth_userid:$password@/api/v1/erm/sushi_service")->status_is(403); >+ >+ # Authorised access test >+ my $q = encode_json( >+ { >+ "url" => $service_url >+ } >+ ); >+ my $sushi_service = $t->get_ok("//$userid:$password@/api/v1/erm/sushi_service?q=$q")->status_is(200) >+ ->tx->res->json; >+ is_deeply( $sushi_service, $expected_response ); >+}; >-- >2.37.1 (Apple Git-137.1)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35218
:
158527
|
158545
|
158546
|
158547