Bug 31351: (QA follow-up) Adjust tests accordingly

Test plan:
Run t/db_dependent/Koha/BackgroundJob.t
Run t/db_dependent/Koha/BackgroundJobs.t
Prove t/db_dependent/Koha/BackgroundJobs

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Marcel de Rooy 2022-09-07 12:29:52 +00:00 committed by Tomas Cohen Arazi
parent 202db89f83
commit 727193dead
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
4 changed files with 14 additions and 21 deletions

View file

@ -25,8 +25,6 @@ use Koha::Database;
use Koha::BackgroundJobs;
use Koha::BackgroundJob::BatchUpdateItem;
use JSON qw( decode_json encode_json );
use t::lib::Mocks;
use t::lib::Mocks::Logger;
use t::lib::TestBuilder;
@ -108,7 +106,7 @@ subtest 'enqueue() tests' => sub {
is( $job->size, 3, 'Three steps' );
is( $job->status, 'new', 'Initial status set correctly' );
is( $job->borrowernumber, $patron->id, 'Borrowernumber set from userenv' );
is_deeply( decode_json( $job->context ), $job_context, 'Context set from userenv + interface' );
is_deeply( $job->json->decode( $job->context ), $job_context, 'Context set from userenv + interface' );
$schema->storage->txn_rollback;
};
@ -150,14 +148,14 @@ subtest 'start(), step() and finish() tests' => sub {
is( $job->status, 'cancelled', "'finish' leaves 'cancelled' untouched" );
isnt( $job->ended_on, undef, 'ended_on set' );
is_deeply( decode_json( $job->data ), $data );
is_deeply( $job->json->decode( $job->data ), $data );
$job->status('started')->store;
$job->finish( $data );
is( $job->status, 'finished' );
isnt( $job->ended_on, undef, 'ended_on set' );
is_deeply( decode_json( $job->data ), $data );
is_deeply( $job->json->decode( $job->data ), $data );
throws_ok
{ $job->start; }
@ -224,15 +222,14 @@ subtest 'process tests' => sub {
is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" );
# Manually add a job (->new->store) without context
my $json = $job->json; # sorry, quickly borrowing your json object
my $data = $json->encode({ a => 'a', b => 'b' });
my $incomplete_job = t::lib::Koha::BackgroundJob::BatchTest->new(
{ status => 'new',
size => 1,
borrowernumber => $patron->borrowernumber,
type => 'batch_test',
data => encode_json {
a => 'a',
b => 'b',
},
data => $data,
}
)->store;
@ -254,6 +251,6 @@ subtest 'decoded_data() and set_encoded_data() tests' => sub {
$job->set_encoded_data( $data );
is_deeply( decode_json($job->data), $data );
is_deeply( $job->json->decode($job->data), $data );
is_deeply( $job->decoded_data, $data );
};

View file

@ -21,7 +21,6 @@ use Modern::Perl;
use Test::More tests => 12;
use Test::MockModule;
use JSON qw( decode_json );
use Koha::Database;
use Koha::BackgroundJobs;
@ -60,7 +59,7 @@ my $job_id = t::lib::Koha::BackgroundJob::BatchTest->new->enqueue(
# Enqueuing a new job
my $new_job = Koha::BackgroundJobs->find($job_id);
ok( $new_job, 'New job correctly enqueued' );
is_deeply( decode_json( $new_job->data ),
is_deeply( $new_job->json->decode( $new_job->data ),
$data, 'data retrieved and json encoded correctly' );
is( t::lib::Dates::compare( $new_job->enqueued_on, dt_from_string ),
0, 'enqueued_on correctly filled with now()' );

View file

@ -21,7 +21,6 @@ use Modern::Perl;
use Test::More tests => 1;
use Test::MockModule;
use JSON qw( encode_json decode_json );
use Koha::Database;
use Koha::BackgroundJobs;
@ -50,16 +49,15 @@ subtest "Exceptions must be stringified" => sub {
size => 1,
borrowernumber => $patron->borrowernumber,
type => 'batch_biblio_record_modification',
data => encode_json {
record_ids => [ $biblio->biblionumber ],
}
}
)->store;
);
my $data = $job->json->encode({ record_ids => [ $biblio->biblionumber ] });
$job->data( $data )->store;
$job = Koha::BackgroundJobs->find( $job->id );
$job->process(
{ job_id => $job->id, record_ids => [ $biblio->biblionumber ] } );
my $data = decode_json $job->get_from_storage->data;
$data = $job->json->decode( $job->get_from_storage->data );
is_deeply(
$data->{messages}->[0],
{

View file

@ -16,7 +16,6 @@ package t::lib::Koha::BackgroundJob::BatchTest;
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use JSON qw( decode_json encode_json );
use Koha::BackgroundJobs;
use Koha::DateUtils qw( dt_from_string );
@ -57,12 +56,12 @@ sub process {
$self->progress( ++$job_progress )->store;
}
my $job_data = decode_json $self->data;
my $job_data = $self->json->decode($self->data);
$job_data->{messages} = \@messages;
$job_data->{report} = $report;
$self->ended_on(dt_from_string)
->data(encode_json $job_data);
->data( $self->json->encode($job_data) );
$self->status('finished') if $self->status ne 'cancelled';
$self->store;
}