Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 2; |
20 |
use Test::More tests => 3; |
21 |
|
21 |
|
22 |
use Koha::Database; |
22 |
use Koha::Database; |
23 |
use Koha::BackgroundJobs; |
23 |
use Koha::BackgroundJobs; |
Lines 36-41
my $schema = Koha::Database->new->schema;
Link Here
|
36 |
my $builder = t::lib::TestBuilder->new; |
36 |
my $builder = t::lib::TestBuilder->new; |
37 |
|
37 |
|
38 |
my $sushi_response_errors = { |
38 |
my $sushi_response_errors = { |
|
|
39 |
'invalid_date_arguments' => '{"message":"Invalid Date Arguments","code":3020,"severity":"Error"}', |
39 |
'invalid_api_key' => '{"Code": 2020, "Severity": "Error", "Message": "API Key Invalid"}', |
40 |
'invalid_api_key' => '{"Code": 2020, "Severity": "Error", "Message": "API Key Invalid"}', |
40 |
}; |
41 |
}; |
41 |
|
42 |
|
Lines 67-72
subtest 'enqueue() tests' => sub {
Link Here
|
67 |
$schema->storage->txn_rollback; |
68 |
$schema->storage->txn_rollback; |
68 |
}; |
69 |
}; |
69 |
|
70 |
|
|
|
71 |
subtest 'invalid_date_arguments() tests' => sub { |
72 |
|
73 |
plan tests => 3; |
74 |
|
75 |
$schema->storage->txn_begin; |
76 |
|
77 |
my $ua = Test::MockModule->new('LWP::UserAgent'); |
78 |
$ua->mock('simple_request', sub { |
79 |
return mock_sushi_response({'error'=>'invalid_date_arguments'}); |
80 |
}); |
81 |
|
82 |
my $usage_data_provider = $builder->build_object( |
83 |
{ class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); |
84 |
|
85 |
my $job_args = { |
86 |
ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, |
87 |
report_type => 'TR_J1', |
88 |
begin_date => '2023-08-01', |
89 |
end_date => '2023-09-30', |
90 |
ud_provider_name => $usage_data_provider->name, |
91 |
}; |
92 |
|
93 |
my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue($job_args); |
94 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
95 |
$job->process( $job_args ); |
96 |
|
97 |
is( $job->{messages}[0]->{message}, decode_json($sushi_response_errors->{invalid_date_arguments})->{severity} . ' - ' . decode_json($sushi_response_errors->{invalid_date_arguments})->{message},'SUSHI error invalid_date_arguments is stored on job messages correctly' ); |
98 |
is( $job->{messages}[0]->{type},'error','SUSHI error invalid_date_arguments is stored on job messages correctly' ); |
99 |
is( $job->{messages}[0]->{code},decode_json($sushi_response_errors->{invalid_date_arguments})->{code},'SUSHI error invalid_date_arguments is stored on job messages correctly' ); |
100 |
|
101 |
$schema->storage->txn_rollback; |
102 |
}; |
103 |
|
70 |
subtest 'invalid_api_key() tests' => sub { |
104 |
subtest 'invalid_api_key() tests' => sub { |
71 |
|
105 |
|
72 |
plan tests => 3; |
106 |
plan tests => 3; |
73 |
- |
|
|