View | Details | Raw Unified | Return to bug 35757
Collapse All | Expand All

(-)a/t/db_dependent/api/v1/erm_counter_registries.t (-96 / +24 lines)
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
};
(-)a/t/db_dependent/api/v1/erm_sushi_services.t (-34 / +34 lines)
Lines 26-31 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;
Lines 35-76 my $builder = t::lib::TestBuilder->new; Link Here
35
my $t = Test::Mojo->new('Koha::REST::V1');
36
my $t = Test::Mojo->new('Koha::REST::V1');
36
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
37
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
37
38
39
# The Usage statistics module uses an external API to fetch data from the counter registry
40
# 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
41
38
subtest 'get() tests' => sub {
42
subtest 'get() tests' => sub {
39
    plan tests => 5;
43
    plan tests => 5;
40
44
41
    my $service_url = "https://registry.projectcounter.org/api/v1/sushi-service/b94bc981-fa16-4bf6-ba5f-6c113f7ffa0b/";
45
    my $service_url = "https://registry.projectcounter.org/api/v1/sushi-service/b94bc981-fa16-4bf6-ba5f-6c113f7ffa0b/";
42
    my $expected_response = {
46
    my @expected_fields = (
43
        "api_key_info"     => "",
47
        "api_key_info",
44
        "api_key_required" => 0,
48
        "api_key_required",
45
        "contact"          => {
49
        "contact",
46
            "email"    => 'chadmovalli@ebsco.com',
50
        "counter_release",
47
            "form_url" => "",
51
        "credentials_auto_expire",
48
            "person"   => "Chad Movalli",
52
        "credentials_auto_expire_info",
49
            "phone"    => ""
53
        "customer_id_info",
50
        },
54
        "customizations_in_place",
51
        "counter_release"              => "5",
55
        "customizations_info",
52
        "credentials_auto_expire"      => 0,
56
        "data_host",
53
        "credentials_auto_expire_info" => "",
57
        "id",
54
        "customer_id_info"             => "This is your EBSCOhost Customer ID",
58
        "ip_address_authorization",
55
        "customizations_in_place"      => 0,
59
        "ip_address_authorization_info",
56
        "customizations_info"          => "",
60
        "migrations",
57
        "data_host"                    =>
61
        "notification_count",
58
            "https:\/\/registry.projectcounter.org\/api\/v1\/usage-data-host\/72a35413-6fcd-44f2-8bce-0c7b2373e33f\/",
62
        "notifications_url",
59
        "id"                            => "b94bc981-fa16-4bf6-ba5f-6c113f7ffa0b",
63
        "platform_attr_required",
60
        "ip_address_authorization"      => 0,
64
        "platform_specific_info",
61
        "ip_address_authorization_info" => "",
65
        "request_volume_limits_applied",
62
        "notification_count"            => 1,
66
        "request_volume_limits_info",
63
        "notifications_url"             =>
67
        "requestor_id_info",
64
            "https:\/\/registry.projectcounter.org\/api\/v1\/sushi-service\/b94bc981-fa16-4bf6-ba5f-6c113f7ffa0b\/notification\/",
68
        "requestor_id_required",
65
        "platform_attr_required"        => 0,
69
        "url",
66
        "platform_specific_info"        => "",
70
    );
67
        "request_volume_limits_applied" => 0,
68
        "request_volume_limits_info"    => "",
69
        "requestor_id_info"             =>
70
            "Customers generate their Requestor ID in EBSCOAdmin on the SUSHI Authentication tab within the COUNTER R5 Reports section.",
71
        "requestor_id_required" => 1,
72
        "url"                   => "https:\/\/sushi.ebscohost.com\/R5"
73
    };
74
71
75
    my $librarian = $builder->build_object(
72
    my $librarian = $builder->build_object(
76
        {
73
        {
Lines 98-102 subtest 'get() tests' => sub { Link Here
98
    # Authorised access test
95
    # Authorised access test
99
    my $q             = encode_json( { "url" => $service_url } );
96
    my $q             = encode_json( { "url" => $service_url } );
100
    my $sushi_service = $t->get_ok("//$userid:$password@/api/v1/erm/sushi_service?q=$q")->status_is(200)->tx->res->json;
97
    my $sushi_service = $t->get_ok("//$userid:$password@/api/v1/erm/sushi_service?q=$q")->status_is(200)->tx->res->json;
101
    is_deeply( $sushi_service, $expected_response );
98
99
    my @response_fields = map { $_ } keys %$sushi_service;
100
    my @new_fields_in_response = array_minus( @response_fields, @expected_fields );
101
102
    is(scalar(@new_fields_in_response), 0, 'The response fields match the expected fields');
102
};
103
};
103
- 

Return to bug 35757