Lines 41-47
my $sushi_response_errors = {
Link Here
|
41 |
}; |
41 |
}; |
42 |
|
42 |
|
43 |
my $sushi_response_exceptions = { |
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"}]}', |
44 |
'multiple_exceptions' => |
|
|
45 |
'{"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 |
}; |
46 |
|
47 |
|
47 |
subtest 'enqueue() tests' => sub { |
48 |
subtest 'enqueue() tests' => sub { |
Lines 173-204
subtest 'multiple_exceptions() tests' => sub {
Link Here
|
173 |
$schema->storage->txn_begin; |
174 |
$schema->storage->txn_begin; |
174 |
|
175 |
|
175 |
my $ua = Test::MockModule->new('LWP::UserAgent'); |
176 |
my $ua = Test::MockModule->new('LWP::UserAgent'); |
176 |
$ua->mock('simple_request', sub { |
177 |
$ua->mock( |
177 |
return mock_sushi_response({'exception'=>'multiple_exceptions'}); |
178 |
'simple_request', |
178 |
}); |
179 |
sub { |
|
|
180 |
return mock_sushi_response( { 'exception' => 'multiple_exceptions' } ); |
181 |
} |
182 |
); |
179 |
|
183 |
|
180 |
my $usage_data_provider = $builder->build_object( |
184 |
my $usage_data_provider = $builder->build_object( |
181 |
{ class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); |
185 |
{ class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); |
182 |
|
186 |
|
183 |
my $job_args = { |
187 |
my $job_args = { |
184 |
ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, |
188 |
ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, |
185 |
report_type => 'TR_J1', |
189 |
report_type => 'TR_J1', |
186 |
begin_date => '2023-08-01', |
190 |
begin_date => '2023-08-01', |
187 |
end_date => '2023-09-30', |
191 |
end_date => '2023-09-30', |
188 |
ud_provider_name => $usage_data_provider->name, |
192 |
ud_provider_name => $usage_data_provider->name, |
189 |
}; |
193 |
}; |
190 |
|
194 |
|
191 |
my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue($job_args); |
195 |
my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue($job_args); |
192 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
196 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
193 |
$job->process( $job_args ); |
197 |
$job->process($job_args); |
194 |
|
198 |
|
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' ); |
199 |
is( |
196 |
is( $job->{messages}[0]->{type},'error','SUSHI error multiple_exceptions are stored on job messages correctly' ); |
200 |
$job->{messages}[0]->{message}, |
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' ); |
201 |
decode_json( $sushi_response_exceptions->{multiple_exceptions} )->{Exceptions}[0]->{Message} . ' - ' |
|
|
202 |
. decode_json( $sushi_response_exceptions->{multiple_exceptions} )->{Exceptions}[0]->{Data}, |
203 |
'SUSHI exceptions multiple_exceptions are stored on job messages correctly' |
204 |
); |
205 |
is( $job->{messages}[0]->{type}, 'error', 'SUSHI error multiple_exceptions are stored on job messages correctly' ); |
206 |
is( |
207 |
$job->{messages}[0]->{code}, |
208 |
decode_json( $sushi_response_exceptions->{multiple_exceptions} )->{Exceptions}[0]->{Code}, |
209 |
'SUSHI error multiple_exceptions are stored on job messages correctly' |
210 |
); |
198 |
|
211 |
|
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' ); |
212 |
is( |
200 |
is( $job->{messages}[1]->{type},'error','SUSHI error multiple_exceptions are stored on job messages correctly' ); |
213 |
$job->{messages}[1]->{message}, |
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' ); |
214 |
decode_json( $sushi_response_exceptions->{multiple_exceptions} )->{Exceptions}[1]->{Message} . ' - ' |
|
|
215 |
. decode_json( $sushi_response_exceptions->{multiple_exceptions} )->{Exceptions}[1]->{Data}, |
216 |
'SUSHI exceptions multiple_exceptions are stored on job messages correctly' |
217 |
); |
218 |
is( $job->{messages}[1]->{type}, 'error', 'SUSHI error multiple_exceptions are stored on job messages correctly' ); |
219 |
is( |
220 |
$job->{messages}[1]->{code}, |
221 |
decode_json( $sushi_response_exceptions->{multiple_exceptions} )->{Exceptions}[1]->{Code}, |
222 |
'SUSHI error multiple_exceptions are stored on job messages correctly' |
223 |
); |
202 |
|
224 |
|
203 |
$schema->storage->txn_rollback; |
225 |
$schema->storage->txn_rollback; |
204 |
}; |
226 |
}; |
205 |
- |
|
|