|
Lines 17-24
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
|
|
20 |
use Test::MockModule; |
| 20 |
use Test::NoWarnings; |
21 |
use Test::NoWarnings; |
| 21 |
use Test::More tests => 2; |
22 |
use Test::More tests => 3; |
| 22 |
|
23 |
|
| 23 |
use Koha::Database; |
24 |
use Koha::Database; |
| 24 |
use Koha::BackgroundJobs; |
25 |
use Koha::BackgroundJobs; |
|
Lines 51-53
subtest 'enqueue() tests' => sub {
Link Here
|
| 51 |
|
52 |
|
| 52 |
$schema->storage->txn_rollback; |
53 |
$schema->storage->txn_rollback; |
| 53 |
}; |
54 |
}; |
| 54 |
- |
55 |
|
|
|
56 |
subtest 'process() tests' => sub { |
| 57 |
|
| 58 |
plan tests => 4; |
| 59 |
|
| 60 |
$schema->storage->txn_begin; |
| 61 |
|
| 62 |
my $batch_return = []; |
| 63 |
my $output_module = Test::MockModule->new('Koha::BackgroundJob::MARCImportCommitBatch'); |
| 64 |
$output_module->mock( |
| 65 |
'BatchCommitRecords', |
| 66 |
sub { |
| 67 |
return @{$batch_return}; |
| 68 |
} |
| 69 |
); |
| 70 |
my $import_batch = $builder->build_object( { class => 'Koha::ImportBatches' } ); |
| 71 |
|
| 72 |
# Add two records |
| 73 |
$builder->build_object( { class => 'Koha::Import::Records', value => { import_batch_id => $import_batch->id } } ); |
| 74 |
$builder->build_object( { class => 'Koha::Import::Records', value => { import_batch_id => $import_batch->id } } ); |
| 75 |
|
| 76 |
my $job_id = Koha::BackgroundJob::MARCImportCommitBatch->new->enqueue( { import_batch_id => $import_batch->id } ); |
| 77 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
| 78 |
|
| 79 |
@{$batch_return} = ( 0, 0, 0, 0, 0, 2 ); |
| 80 |
$job->process( { import_batch_id => $import_batch->id } ); |
| 81 |
$job->discard_changes; |
| 82 |
is( $job->status, 'finished', 'A job where all records are ignored is a success' ); |
| 83 |
|
| 84 |
$job->status('new')->store; |
| 85 |
@{$batch_return} = ( 1, 1, 0, 0, 0, 1 ); |
| 86 |
$job->process( { import_batch_id => $import_batch->id } ); |
| 87 |
$job->discard_changes; |
| 88 |
is( $job->status, 'failed', 'A job where the record counts do not match is failed' ); |
| 89 |
is( $job->size, '2', 'Size is based on number of records' ); |
| 90 |
is( $job->progress, '3', 'Progress is the total number of records processed, including added/updated/ignored' ); |
| 91 |
$schema->storage->txn_rollback; |
| 92 |
}; |