|
Lines 232-262
subtest 'is_redirect() tests' => sub {
Link Here
|
| 232 |
$schema->storage->txn_begin; |
232 |
$schema->storage->txn_begin; |
| 233 |
|
233 |
|
| 234 |
my $ua = Test::MockModule->new('LWP::UserAgent'); |
234 |
my $ua = Test::MockModule->new('LWP::UserAgent'); |
| 235 |
$ua->mock('simple_request', sub { |
235 |
$ua->mock( |
|
|
236 |
'simple_request', |
| 237 |
sub { |
| 236 |
return mock_HTTP_redirect(); |
238 |
return mock_HTTP_redirect(); |
| 237 |
}); |
239 |
} |
| 238 |
$ua->mock('get', sub { |
240 |
); |
| 239 |
return mock_sushi_response({'error'=>'invalid_api_key'}); |
241 |
$ua->mock( |
| 240 |
}); |
242 |
'get', |
|
|
243 |
sub { |
| 244 |
return mock_sushi_response( { 'error' => 'invalid_api_key' } ); |
| 245 |
} |
| 246 |
); |
| 241 |
|
247 |
|
| 242 |
my $usage_data_provider = $builder->build_object( |
248 |
my $usage_data_provider = $builder->build_object( |
| 243 |
{ class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); |
249 |
{ class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); |
| 244 |
|
250 |
|
| 245 |
my $job_args = { |
251 |
my $job_args = { |
| 246 |
ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, |
252 |
ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, |
| 247 |
report_type => 'TR_J1', |
253 |
report_type => 'TR_J1', |
| 248 |
begin_date => '2023-08-01', |
254 |
begin_date => '2023-08-01', |
| 249 |
end_date => '2023-09-30', |
255 |
end_date => '2023-09-30', |
| 250 |
ud_provider_name => $usage_data_provider->name, |
256 |
ud_provider_name => $usage_data_provider->name, |
| 251 |
}; |
257 |
}; |
| 252 |
|
258 |
|
| 253 |
my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue($job_args); |
259 |
my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue($job_args); |
| 254 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
260 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
| 255 |
$job->process( $job_args ); |
261 |
$job->process($job_args); |
| 256 |
|
262 |
|
| 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' ); |
263 |
is( |
| 258 |
is( $job->{messages}[0]->{type},'error','SUSHI error invalid_date_arguments is stored on job messages correctly' ); |
264 |
$job->{messages}[0]->{message}, |
| 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' ); |
265 |
decode_json( $sushi_response_errors->{invalid_api_key} )->{Severity} . ' - ' |
|
|
266 |
. decode_json( $sushi_response_errors->{invalid_api_key} )->{Message}, |
| 267 |
'SUSHI error invalid_date_arguments is stored on job messages correctly' |
| 268 |
); |
| 269 |
is( |
| 270 |
$job->{messages}[0]->{type}, 'error', |
| 271 |
'SUSHI error invalid_date_arguments is stored on job messages correctly' |
| 272 |
); |
| 273 |
is( |
| 274 |
$job->{messages}[0]->{code}, decode_json( $sushi_response_errors->{invalid_api_key} )->{Code}, |
| 275 |
'SUSHI error invalid_date_arguments is stored on job messages correctly' |
| 276 |
); |
| 260 |
|
277 |
|
| 261 |
$schema->storage->txn_rollback; |
278 |
$schema->storage->txn_rollback; |
| 262 |
}; |
279 |
}; |
|
Lines 296-314
sub mock_sushi_response {
Link Here
|
| 296 |
sub mock_HTTP_redirect { |
313 |
sub mock_HTTP_redirect { |
| 297 |
my $response = Test::MockObject->new(); |
314 |
my $response = Test::MockObject->new(); |
| 298 |
|
315 |
|
| 299 |
$response->mock('code', sub { |
316 |
$response->mock( |
| 300 |
return 301; |
317 |
'code', |
| 301 |
}); |
318 |
sub { |
| 302 |
$response->mock('is_error', sub { |
319 |
return 301; |
| 303 |
return 0; |
320 |
} |
| 304 |
}); |
321 |
); |
| 305 |
$response->mock('is_redirect', sub { |
322 |
$response->mock( |
| 306 |
return 1; |
323 |
'is_error', |
| 307 |
}); |
324 |
sub { |
| 308 |
$response->mock('header', sub { |
325 |
return 0; |
| 309 |
return 'www.whatever.com'; |
326 |
} |
| 310 |
}); |
327 |
); |
| 311 |
$response->mock('decoded_content', sub { |
328 |
$response->mock( |
| 312 |
return 'Moved permanently'; |
329 |
'is_redirect', |
| 313 |
}); |
330 |
sub { |
|
|
331 |
return 1; |
| 332 |
} |
| 333 |
); |
| 334 |
$response->mock( |
| 335 |
'header', |
| 336 |
sub { |
| 337 |
return 'www.whatever.com'; |
| 338 |
} |
| 339 |
); |
| 340 |
$response->mock( |
| 341 |
'decoded_content', |
| 342 |
sub { |
| 343 |
return 'Moved permanently'; |
| 344 |
} |
| 345 |
); |
| 314 |
} |
346 |
} |
| 315 |
- |
|
|