Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 4; |
20 |
use Test::More tests => 5; |
21 |
|
21 |
|
22 |
use Koha::Database; |
22 |
use Koha::Database; |
23 |
use Koha::BackgroundJobs; |
23 |
use Koha::BackgroundJobs; |
Lines 225-230
subtest 'multiple_exceptions() tests' => sub {
Link Here
|
225 |
$schema->storage->txn_rollback; |
225 |
$schema->storage->txn_rollback; |
226 |
}; |
226 |
}; |
227 |
|
227 |
|
|
|
228 |
subtest 'is_redirect() tests' => sub { |
229 |
|
230 |
plan tests => 3; |
231 |
|
232 |
$schema->storage->txn_begin; |
233 |
|
234 |
my $ua = Test::MockModule->new('LWP::UserAgent'); |
235 |
$ua->mock('simple_request', sub { |
236 |
return mock_HTTP_redirect(); |
237 |
}); |
238 |
$ua->mock('get', sub { |
239 |
return mock_sushi_response({'error'=>'invalid_api_key'}); |
240 |
}); |
241 |
|
242 |
my $usage_data_provider = $builder->build_object( |
243 |
{ class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); |
244 |
|
245 |
my $job_args = { |
246 |
ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, |
247 |
report_type => 'TR_J1', |
248 |
begin_date => '2023-08-01', |
249 |
end_date => '2023-09-30', |
250 |
ud_provider_name => $usage_data_provider->name, |
251 |
}; |
252 |
|
253 |
my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue($job_args); |
254 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
255 |
$job->process( $job_args ); |
256 |
|
257 |
is( $job->{messages}[0]->{message}, decode_json($sushi_response_errors->{invalid_api_key})->{Severity} . ' - ' . decode_json($sushi_response_errors->{invalid_api_key})->{Message},'SUSHI error invalid_date_arguments is stored on job messages correctly' ); |
258 |
is( $job->{messages}[0]->{type},'error','SUSHI error invalid_date_arguments is stored on job messages correctly' ); |
259 |
is( $job->{messages}[0]->{code},decode_json($sushi_response_errors->{invalid_api_key})->{Code},'SUSHI error invalid_date_arguments is stored on job messages correctly' ); |
260 |
|
261 |
$schema->storage->txn_rollback; |
262 |
}; |
263 |
|
228 |
sub mock_sushi_response { |
264 |
sub mock_sushi_response { |
229 |
my ($args) = @_; |
265 |
my ($args) = @_; |
230 |
my $response = Test::MockObject->new(); |
266 |
my $response = Test::MockObject->new(); |
Lines 256-258
sub mock_sushi_response {
Link Here
|
256 |
} |
292 |
} |
257 |
); |
293 |
); |
258 |
} |
294 |
} |
259 |
- |
295 |
|
|
|
296 |
sub mock_HTTP_redirect { |
297 |
my $response = Test::MockObject->new(); |
298 |
|
299 |
$response->mock('code', sub { |
300 |
return 301; |
301 |
}); |
302 |
$response->mock('is_error', sub { |
303 |
return 0; |
304 |
}); |
305 |
$response->mock('is_redirect', sub { |
306 |
return 1; |
307 |
}); |
308 |
$response->mock('header', sub { |
309 |
return 'www.whatever.com'; |
310 |
}); |
311 |
$response->mock('decoded_content', sub { |
312 |
return 'Moved permanently'; |
313 |
}); |
314 |
} |