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 162-167
subtest 'invalid_api_key() tests' => sub {
Link Here
|
162 |
$schema->storage->txn_rollback; |
166 |
$schema->storage->txn_rollback; |
163 |
}; |
167 |
}; |
164 |
|
168 |
|
|
|
169 |
subtest 'multiple_exceptions() tests' => sub { |
170 |
|
171 |
plan tests => 6; |
172 |
|
173 |
$schema->storage->txn_begin; |
174 |
|
175 |
my $ua = Test::MockModule->new('LWP::UserAgent'); |
176 |
$ua->mock('simple_request', sub { |
177 |
return mock_sushi_response({'exception'=>'multiple_exceptions'}); |
178 |
}); |
179 |
|
180 |
my $usage_data_provider = $builder->build_object( |
181 |
{ class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); |
182 |
|
183 |
my $job_args = { |
184 |
ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, |
185 |
report_type => 'TR_J1', |
186 |
begin_date => '2023-08-01', |
187 |
end_date => '2023-09-30', |
188 |
ud_provider_name => $usage_data_provider->name, |
189 |
}; |
190 |
|
191 |
my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue($job_args); |
192 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
193 |
$job->process( $job_args ); |
194 |
|
195 |
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' ); |
196 |
is( $job->{messages}[0]->{type},'error','SUSHI error multiple_exceptions are stored on job messages correctly' ); |
197 |
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' ); |
198 |
|
199 |
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' ); |
200 |
is( $job->{messages}[1]->{type},'error','SUSHI error multiple_exceptions are stored on job messages correctly' ); |
201 |
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' ); |
202 |
|
203 |
$schema->storage->txn_rollback; |
204 |
}; |
205 |
|
165 |
sub mock_sushi_response { |
206 |
sub mock_sushi_response { |
166 |
my ($args) = @_; |
207 |
my ($args) = @_; |
167 |
my $response = Test::MockObject->new(); |
208 |
my $response = Test::MockObject->new(); |
Lines 187-193
sub mock_sushi_response {
Link Here
|
187 |
$response->mock( |
228 |
$response->mock( |
188 |
'decoded_content', |
229 |
'decoded_content', |
189 |
sub { |
230 |
sub { |
190 |
return $sushi_response_errors->{ $args->{error} }; |
231 |
return $args->{error} |
|
|
232 |
? $sushi_response_errors->{ $args->{error} } |
233 |
: $sushi_response_exceptions->{ $args->{exception} }; |
191 |
} |
234 |
} |
192 |
); |
235 |
); |
193 |
} |
236 |
} |
194 |
- |
|
|