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

(-)a/t/db_dependent/Koha/BackgroundJob/ErmSushiHarvester.t (-3 / +43 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 3;
20
use Test::More tests => 4;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::BackgroundJobs;
23
use Koha::BackgroundJobs;
Lines 40-45 my $sushi_response_errors = { Link Here
40
    'invalid_api_key'        => '{"Code": 2020, "Severity": "Error", "Message": "API Key Invalid"}',
40
    'invalid_api_key'        => '{"Code": 2020, "Severity": "Error", "Message": "API Key Invalid"}',
41
};
41
};
42
42
43
my $sushi_response_exceptions = {
44
    'multiple_exceptions'    => '{"Created":"2024-09-06T10:41:02Z","Created_By":"Test Services","Customer_ID":"Test_customer_id","Report_ID":"TR_J1","Release":"5","Report_Name":"Journal Requests (Excluding OA_Gold)","Institution_Name":"Test Institution","Report_Filters":[{"Name":"Begin_Date","Value":"2024-06-01"},{"Name":"End_Date","Value":"2024-08-31"}],"Exceptions":[{"Code":3050,"Severity":"Warning","Message":"Parameter Not Recognized in this Context","Data":"Parameter api_key is not recognized"},{"Code":3070,"Severity":"Error","Message":"Required ReportFilter Missing","Data":"Required parameter Platform is missing and should be one of:sd|sc|ev|em|ck"}]}',
45
};
46
43
subtest 'enqueue() tests' => sub {
47
subtest 'enqueue() tests' => sub {
44
48
45
    plan tests => 3;
49
    plan tests => 3;
Lines 134-139 subtest 'invalid_api_key() tests' => sub { Link Here
134
    $schema->storage->txn_rollback;
138
    $schema->storage->txn_rollback;
135
};
139
};
136
140
141
subtest 'multiple_exceptions() tests' => sub {
142
143
    plan tests => 6;
144
145
    $schema->storage->txn_begin;
146
147
    my $ua = Test::MockModule->new('LWP::UserAgent');
148
    $ua->mock('simple_request', sub {
149
            return mock_sushi_response({'exception'=>'multiple_exceptions'});
150
    });
151
152
    my $usage_data_provider = $builder->build_object(
153
        { class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } );
154
155
    my $job_args = {
156
            ud_provider_id   => $usage_data_provider->erm_usage_data_provider_id,
157
            report_type      => 'TR_J1',
158
            begin_date       => '2023-08-01',
159
            end_date         => '2023-09-30',
160
            ud_provider_name => $usage_data_provider->name,
161
        };
162
163
    my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue($job_args);
164
    my $job = Koha::BackgroundJobs->find($job_id)->_derived_class;
165
    $job->process( $job_args );
166
167
    is( $job->{messages}[0]->{message}, decode_json($sushi_response_exceptions->{multiple_exceptions})->{Exceptions}[0]->{Message} . ' - ' . decode_json($sushi_response_exceptions->{multiple_exceptions})->{Exceptions}[0]->{Data},'SUSHI exceptions multiple_exceptions are stored on job messages correctly' );
168
    is( $job->{messages}[0]->{type},'error','SUSHI error multiple_exceptions are stored on job messages correctly' );
169
    is( $job->{messages}[0]->{code},decode_json($sushi_response_exceptions->{multiple_exceptions})->{Exceptions}[0]->{Code},'SUSHI error multiple_exceptions are stored on job messages correctly' );
170
171
    is( $job->{messages}[1]->{message}, decode_json($sushi_response_exceptions->{multiple_exceptions})->{Exceptions}[1]->{Message} . ' - ' . decode_json($sushi_response_exceptions->{multiple_exceptions})->{Exceptions}[1]->{Data},'SUSHI exceptions multiple_exceptions are stored on job messages correctly' );
172
    is( $job->{messages}[1]->{type},'error','SUSHI error multiple_exceptions are stored on job messages correctly' );
173
    is( $job->{messages}[1]->{code},decode_json($sushi_response_exceptions->{multiple_exceptions})->{Exceptions}[1]->{Code},'SUSHI error multiple_exceptions are stored on job messages correctly' );
174
175
    $schema->storage->txn_rollback;
176
};
177
137
sub mock_sushi_response {
178
sub mock_sushi_response {
138
    my ($args) = @_;
179
    my ($args) = @_;
139
    my $response = Test::MockObject->new();
180
    my $response = Test::MockObject->new();
Lines 148-153 sub mock_sushi_response { Link Here
148
        return 0;
189
        return 0;
149
    });
190
    });
150
    $response->mock('decoded_content', sub {
191
    $response->mock('decoded_content', sub {
151
        return $sushi_response_errors->{$args->{error}};
192
        return $args->{error} ? $sushi_response_errors->{$args->{error}} : $sushi_response_exceptions->{$args->{exception}};
152
    });
193
    });
153
}
194
}
154
- 

Return to bug 37856