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 175-180
subtest 'multiple_exceptions() tests' => sub {
Link Here
|
175 |
$schema->storage->txn_rollback; |
175 |
$schema->storage->txn_rollback; |
176 |
}; |
176 |
}; |
177 |
|
177 |
|
|
|
178 |
subtest 'is_redirect() tests' => sub { |
179 |
|
180 |
plan tests => 3; |
181 |
|
182 |
$schema->storage->txn_begin; |
183 |
|
184 |
my $ua = Test::MockModule->new('LWP::UserAgent'); |
185 |
$ua->mock('simple_request', sub { |
186 |
return mock_HTTP_redirect(); |
187 |
}); |
188 |
$ua->mock('get', sub { |
189 |
return mock_sushi_response({'error'=>'invalid_api_key'}); |
190 |
}); |
191 |
|
192 |
my $usage_data_provider = $builder->build_object( |
193 |
{ class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); |
194 |
|
195 |
my $job_args = { |
196 |
ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, |
197 |
report_type => 'TR_J1', |
198 |
begin_date => '2023-08-01', |
199 |
end_date => '2023-09-30', |
200 |
ud_provider_name => $usage_data_provider->name, |
201 |
}; |
202 |
|
203 |
my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue($job_args); |
204 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
205 |
$job->process( $job_args ); |
206 |
|
207 |
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' ); |
208 |
is( $job->{messages}[0]->{type},'error','SUSHI error invalid_date_arguments is stored on job messages correctly' ); |
209 |
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' ); |
210 |
|
211 |
$schema->storage->txn_rollback; |
212 |
}; |
213 |
|
178 |
sub mock_sushi_response { |
214 |
sub mock_sushi_response { |
179 |
my ($args) = @_; |
215 |
my ($args) = @_; |
180 |
my $response = Test::MockObject->new(); |
216 |
my $response = Test::MockObject->new(); |
Lines 191-194
sub mock_sushi_response {
Link Here
|
191 |
$response->mock('decoded_content', sub { |
227 |
$response->mock('decoded_content', sub { |
192 |
return $args->{error} ? $sushi_response_errors->{$args->{error}} : $sushi_response_exceptions->{$args->{exception}}; |
228 |
return $args->{error} ? $sushi_response_errors->{$args->{error}} : $sushi_response_exceptions->{$args->{exception}}; |
193 |
}); |
229 |
}); |
|
|
230 |
} |
231 |
|
232 |
sub mock_HTTP_redirect { |
233 |
my $response = Test::MockObject->new(); |
234 |
|
235 |
$response->mock('code', sub { |
236 |
return 301; |
237 |
}); |
238 |
$response->mock('is_error', sub { |
239 |
return 0; |
240 |
}); |
241 |
$response->mock('is_redirect', sub { |
242 |
return 1; |
243 |
}); |
244 |
$response->mock('header', sub { |
245 |
return 'www.whatever.com'; |
246 |
}); |
247 |
$response->mock('decoded_content', sub { |
248 |
return 'Moved permanently'; |
249 |
}); |
194 |
} |
250 |
} |
195 |
- |
|
|