| Lines 26-35
          use t::lib::TestBuilder;
      
      
        Link Here | 
        
          | 26 | use t::lib::Mocks; | 26 | use t::lib::Mocks; | 
        
          | 27 |  | 27 |  | 
        
          | 28 | use JSON qw(encode_json); | 28 | use JSON qw(encode_json); | 
            
              |  |  | 29 | use Array::Utils qw( array_minus ); | 
        
          | 29 |  | 30 |  | 
        
          | 30 | use Koha::ERM::EUsage::CounterFiles; | 31 | use Koha::ERM::EUsage::CounterFiles; | 
        
          | 31 | use Koha::Database; | 32 | use Koha::Database; | 
        
          | 32 |  | 33 |  | 
            
              |  |  | 34 | # The Usage statistics module uses an external API to fetch data from the counter registry | 
            
              | 35 | # 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 | 
            
              | 36 |  | 
        
          | 33 | my $builder = t::lib::TestBuilder->new; | 37 | my $builder = t::lib::TestBuilder->new; | 
        
          | 34 |  | 38 |  | 
        
          | 35 | my $t = Test::Mojo->new('Koha::REST::V1'); | 39 | my $t = Test::Mojo->new('Koha::REST::V1'); | 
  
    | Lines 38-138
          t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
      
      
        Link Here | 
        
          | 38 | subtest 'get() tests' => sub { | 42 | subtest 'get() tests' => sub { | 
        
          | 39 |     plan tests => 5; | 43 |     plan tests => 5; | 
        
          | 40 |  | 44 |  | 
          
            
              | 41 |     my $expected_response = [ | 45 |     my @expected_fields = ( | 
            
              | 42 |         { | 46 |         "abbrev", | 
            
              | 43 |             "abbrev"          => "EBSCO", | 47 |         "address", | 
            
              | 44 |             "address"         => "EBSCO Information Services\n10 Estes Street\nIpswich, MA 01938", | 48 |         "address_country", | 
            
              | 45 |             "address_country" => { | 49 |         "audited", | 
            
              | 46 |                 "code" => "US", | 50 |         "contact", | 
            
              | 47 |                 "name" => "United States of America" | 51 |         "content_provider_name", | 
            
              | 48 |             }, | 52 |         "host_types", | 
            
              | 49 |             "contact" => { | 53 |         "id", | 
            
              | 50 |                 "email"    => 'chadmovalli@ebsco.com', | 54 |         "name", | 
            
              | 51 |                 "form_url" => "", | 55 |         "reports", | 
            
              | 52 |                 "person"   => "Chad Movalli", | 56 |         "sushi_services", | 
            
              | 53 |                 "phone"    => "" | 57 |         "website", | 
            
              | 54 |             }, | 58 |     ); | 
            
              | 55 |             "content_provider_name" => "EBSCO", |  |  | 
            
              | 56 |             "host_types"            => [ { "name" => "Aggregated_Full_Content" } ], | 
            
              | 57 |             "id"                    => "b2b2736c-2cb9-48ec-91f4-870336acfb1c", | 
            
              | 58 |             "name"                  => "EBSCO Information Services", | 
            
              | 59 |             "reports"               => [ | 
            
              | 60 |                 { | 
            
              | 61 |                     "counter_release" => "5", | 
            
              | 62 |                     "report_id"       => "TR_J4", | 
            
              | 63 |                     "report_name"     => "Title Report - Journal Report 4" | 
            
              | 64 |                 }, | 
            
              | 65 |                 { | 
            
              | 66 |                     "counter_release" => "5", | 
            
              | 67 |                     "report_id"       => "DR_D2", | 
            
              | 68 |                     "report_name"     => "Database Report - Report 2" | 
            
              | 69 |                 }, | 
            
              | 70 |                 { | 
            
              | 71 |                     "counter_release" => "5", | 
            
              | 72 |                     "report_id"       => "TR_J3", | 
            
              | 73 |                     "report_name"     => "Title Report - Journal Report 3" | 
            
              | 74 |                 }, | 
            
              | 75 |                 { | 
            
              | 76 |                     "counter_release" => "5", | 
            
              | 77 |                     "report_id"       => "DR_D1", | 
            
              | 78 |                     "report_name"     => "Database Report - Report 1" | 
            
              | 79 |                 }, | 
            
              | 80 |                 { | 
            
              | 81 |                     "counter_release" => "5", | 
            
              | 82 |                     "report_id"       => "TR_J2", | 
            
              | 83 |                     "report_name"     => "Title Report - Journal Report 2" | 
            
              | 84 |                 }, | 
            
              | 85 |                 { | 
            
              | 86 |                     "counter_release" => "5", | 
            
              | 87 |                     "report_id"       => "PR", | 
            
              | 88 |                     "report_name"     => "Platform Master Report" | 
            
              | 89 |                 }, | 
            
              | 90 |                 { | 
            
              | 91 |                     "counter_release" => "5", | 
            
              | 92 |                     "report_id"       => "TR_B2", | 
            
              | 93 |                     "report_name"     => "Title Report - Book Report 2" | 
            
              | 94 |                 }, | 
            
              | 95 |                 { | 
            
              | 96 |                     "counter_release" => "5", | 
            
              | 97 |                     "report_id"       => "TR_B3", | 
            
              | 98 |                     "report_name"     => "Title Report - Book Report 3" | 
            
              | 99 |                 }, | 
            
              | 100 |                 { | 
            
              | 101 |                     "counter_release" => "5", | 
            
              | 102 |                     "report_id"       => "TR", | 
            
              | 103 |                     "report_name"     => "Title Master Report" | 
            
              | 104 |                 }, | 
            
              | 105 |                 { | 
            
              | 106 |                     "counter_release" => "5", | 
            
              | 107 |                     "report_id"       => "TR_B1", | 
            
              | 108 |                     "report_name"     => "Title Report - Book Report 1" | 
            
              | 109 |                 }, | 
            
              | 110 |                 { | 
            
              | 111 |                     "counter_release" => "5", | 
            
              | 112 |                     "report_id"       => "PR_P1", | 
            
              | 113 |                     "report_name"     => "Platform Report - Report 1" | 
            
              | 114 |                 }, | 
            
              | 115 |                 { | 
            
              | 116 |                     "counter_release" => "5", | 
            
              | 117 |                     "report_id"       => "TR_J1", | 
            
              | 118 |                     "report_name"     => "Title Report - Journal Report 1" | 
            
              | 119 |                 }, | 
            
              | 120 |                 { | 
            
              | 121 |                     "counter_release" => "5", | 
            
              | 122 |                     "report_id"       => "DR", | 
            
              | 123 |                     "report_name"     => "Database Master Report" | 
            
              | 124 |                 } | 
            
              | 125 |             ], | 
            
              | 126 |             "sushi_services" => [ | 
            
              | 127 |                 { | 
            
              | 128 |                     "counter_release" => "5", | 
            
              | 129 |                     "url"             => | 
            
              | 130 |                         "https:\/\/registry.projectcounter.org\/api\/v1\/sushi-service\/b94bc981-fa16-4bf6-ba5f-6c113f7ffa0b\/" | 
            
              | 131 |                 } | 
            
              | 132 |             ], | 
            
              | 133 |             "website" => "https:\/\/www.ebsco.com\/" | 
            
              | 134 |         } | 
            
              | 135 |     ]; | 
        
          | 136 |  | 59 |  | 
        
          | 137 |     my $librarian = $builder->build_object( | 60 |     my $librarian = $builder->build_object( | 
        
          | 138 |         { | 61 |         { | 
  
    | Lines 161-165
          subtest 'get() tests' => sub {
      
      
        Link Here | 
        
          | 161 |     my $q = encode_json( { "name" => "EBSCO Information Services" } ); | 84 |     my $q = encode_json( { "name" => "EBSCO Information Services" } ); | 
        
          | 162 |     my $counter_registry = | 85 |     my $counter_registry = | 
        
          | 163 |         $t->get_ok("//$userid:$password@/api/v1/erm/counter_registry?q=$q")->status_is(200)->tx->res->json; | 86 |         $t->get_ok("//$userid:$password@/api/v1/erm/counter_registry?q=$q")->status_is(200)->tx->res->json; | 
          
            
              | 164 |     is_deeply( $counter_registry, $expected_response ); | 87 |  | 
            
              |  |  | 88 |     my $registry_to_check = @$counter_registry[0]; | 
            
              | 89 |     my @response_fields        = map { $_ } keys %$registry_to_check; | 
            
              | 90 |     my @new_fields_in_response = array_minus( @response_fields, @expected_fields ); | 
            
              | 91 |  | 
            
              | 92 |     is( scalar(@new_fields_in_response), 0, 'The response fields match the expected fields' ); | 
        
          | 165 | }; | 93 | }; |