Bugzilla – Attachment 160746 Details for
Bug 35757
Sushi service and counter registry tests are failing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35757: Fix unit tests for external counter registry API
Bug-35757-Fix-unit-tests-for-external-counter-regi.patch (text/plain), 10.67 KB, created by
Matt Blenkinsop
on 2024-01-10 10:19:39 UTC
(
hide
)
Description:
Bug 35757: Fix unit tests for external counter registry API
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2024-01-10 10:19:39 UTC
Size:
10.67 KB
patch
obsolete
>From e2d8e48b44ebfa67dea3269c4db28db1f5ad987c Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Date: Wed, 10 Jan 2024 10:14:40 +0000 >Subject: [PATCH] Bug 35757: Fix unit tests for external counter registry API > >This patch updates the unit tests for the external counter registry API used in the Usage Statistics module. The intent of the tests is to identify any changes in the external response that could lead to errors in Koha. To do this, the tests now compare the list of hask keys returned in the response with the current definition in Koha, and identifies any new fields that need to be added to the definition. > >Test plan: >prove t/db_dependent/api/v1/erm_counter_registries.t >prove t/db_dependent/api/v1/erm_sushi_services.t >--- > .../api/v1/erm_counter_registries.t | 120 ++++-------------- > t/db_dependent/api/v1/erm_sushi_services.t | 67 +++++----- > 2 files changed, 58 insertions(+), 129 deletions(-) > >diff --git a/t/db_dependent/api/v1/erm_counter_registries.t b/t/db_dependent/api/v1/erm_counter_registries.t >index def1b8c8b0..e80f9e8dcf 100755 >--- a/t/db_dependent/api/v1/erm_counter_registries.t >+++ b/t/db_dependent/api/v1/erm_counter_registries.t >@@ -26,10 +26,14 @@ use t::lib::TestBuilder; > use t::lib::Mocks; > > use JSON qw(encode_json); >+use Array::Utils qw( array_minus ); > > use Koha::ERM::EUsage::CounterFiles; > use Koha::Database; > >+# The Usage statistics module uses an external API to fetch data from the counter registry >+# This test is designed to catch any changes in the response that the API provides so that we can react quickly to ensure the module still functions as expected >+ > my $builder = t::lib::TestBuilder->new; > > my $t = Test::Mojo->new('Koha::REST::V1'); >@@ -38,101 +42,20 @@ 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 @expected_fields = ( >+ "abbrev", >+ "address", >+ "address_country", >+ "audited", >+ "contact", >+ "content_provider_name", >+ "host_types", >+ "id", >+ "name", >+ "reports", >+ "sushi_services", >+ "website", >+ ); > > my $librarian = $builder->build_object( > { >@@ -161,5 +84,10 @@ subtest 'get() tests' => sub { > 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 ); >+ >+ my $registry_to_check = @$counter_registry[0]; >+ my @response_fields = map { $_ } keys %$registry_to_check; >+ my @new_fields_in_response = array_minus( @response_fields, @expected_fields ); >+ >+ is( scalar(@new_fields_in_response), 0, 'The response fields match the expected fields' ); > }; >diff --git a/t/db_dependent/api/v1/erm_sushi_services.t b/t/db_dependent/api/v1/erm_sushi_services.t >index 73d46241d8..0da48fa6e3 100755 >--- a/t/db_dependent/api/v1/erm_sushi_services.t >+++ b/t/db_dependent/api/v1/erm_sushi_services.t >@@ -26,6 +26,7 @@ use t::lib::TestBuilder; > use t::lib::Mocks; > > use JSON qw(encode_json); >+use Array::Utils qw( array_minus ); > > use Koha::ERM::EUsage::CounterFiles; > use Koha::Database; >@@ -35,42 +36,38 @@ my $builder = t::lib::TestBuilder->new; > my $t = Test::Mojo->new('Koha::REST::V1'); > t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); > >+# The Usage statistics module uses an external API to fetch data from the counter registry >+# This test is designed to catch any changes in the response that the API provides so that we can react quickly to ensure the module still functions as expected >+ > 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 @expected_fields = ( >+ "api_key_info", >+ "api_key_required", >+ "contact", >+ "counter_release", >+ "credentials_auto_expire", >+ "credentials_auto_expire_info", >+ "customer_id_info", >+ "customizations_in_place", >+ "customizations_info", >+ "data_host", >+ "id", >+ "ip_address_authorization", >+ "ip_address_authorization_info", >+ "migrations", >+ "notification_count", >+ "notifications_url", >+ "platform_attr_required", >+ "platform_specific_info", >+ "request_volume_limits_applied", >+ "request_volume_limits_info", >+ "requestor_id_info", >+ "requestor_id_required", >+ "url", >+ ); > > my $librarian = $builder->build_object( > { >@@ -98,5 +95,9 @@ subtest 'get() tests' => sub { > # 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 ); >+ >+ my @response_fields = map { $_ } keys %$sushi_service; >+ my @new_fields_in_response = array_minus( @response_fields, @expected_fields ); >+ >+ is(scalar(@new_fields_in_response), 0, 'The response fields match the expected fields'); > }; >-- >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 35757
:
160745
|
160746
|
160747
|
160748
|
160749
|
160779
|
160780
|
160781