Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 1; |
20 |
use Test::More tests => 2; |
21 |
|
21 |
|
22 |
use Koha::Database; |
22 |
use Koha::Database; |
23 |
use Koha::BackgroundJobs; |
23 |
use Koha::BackgroundJobs; |
Lines 29-56
use t::lib::TestBuilder;
Link Here
|
29 |
my $schema = Koha::Database->new->schema; |
29 |
my $schema = Koha::Database->new->schema; |
30 |
my $builder = t::lib::TestBuilder->new; |
30 |
my $builder = t::lib::TestBuilder->new; |
31 |
|
31 |
|
32 |
subtest 'enqueue() tests' => sub { |
32 |
subtest 'enqueue' => sub { |
33 |
|
33 |
|
34 |
plan tests => 5; |
34 |
plan tests => 2; |
35 |
|
35 |
|
36 |
$schema->storage->txn_begin; |
36 |
$schema->storage->txn_begin; |
37 |
|
37 |
|
38 |
# FIXME: Should be an exception |
38 |
# FIXME: Should be an exception |
39 |
my $job_id = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new->enqueue(); |
39 |
my $job_id = |
|
|
40 |
Koha::BackgroundJob::CreateEHoldingsFromBiblios->new->enqueue(); |
40 |
is( $job_id, undef, 'Nothing enqueued if missing params' ); |
41 |
is( $job_id, undef, 'Nothing enqueued if missing params' ); |
41 |
|
42 |
|
42 |
# FIXME: Should be an exception |
43 |
# FIXME: Should be an exception |
43 |
$job_id = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new->enqueue( { record_ids => undef } ); |
44 |
$job_id = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new->enqueue( |
|
|
45 |
{ record_ids => undef } ); |
44 |
is( $job_id, undef, "Nothing enqueued if missing 'package_id' param" ); |
46 |
is( $job_id, undef, "Nothing enqueued if missing 'package_id' param" ); |
45 |
|
47 |
|
46 |
my $record_ids = [ 1, 2 ]; |
48 |
$schema->storage->txn_rollback; |
|
|
49 |
}; |
50 |
|
51 |
subtest 'process' => sub { |
52 |
plan tests => 1; |
53 |
|
54 |
$schema->storage->txn_begin; |
55 |
|
56 |
my $biblio = $builder->build_sample_biblio; |
47 |
|
57 |
|
48 |
$job_id = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new->enqueue( { record_ids => $record_ids, package_id => 'thing' } ); |
58 |
my $package = |
49 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
59 |
Koha::ERM::EHoldings::Package->new( { name => 'a package' } )->store; |
50 |
|
60 |
|
51 |
is( $job->size, scalar @{$record_ids}, 'Size is correct' ); |
61 |
my $job = Koha::BackgroundJob::CreateEHoldingsFromBiblios->new( |
52 |
is( $job->status, 'new', 'Initial status set correctly' ); |
62 |
{ |
53 |
is( $job->queue, 'long_tasks', 'BatchUpdateItem should use the long_tasks queue' ); |
63 |
status => 'new', |
|
|
64 |
type => 'create_eholdings_from_biblios', |
65 |
} |
66 |
)->store; |
67 |
$job = Koha::BackgroundJobs->find( $job->id ); |
68 |
my $data = { |
69 |
record_ids => [ $biblio->biblionumber ], |
70 |
package_id => $package->package_id, |
71 |
}; |
72 |
my $json = $job->json->encode($data); |
73 |
$job->data($json)->store; |
74 |
$job->process($data); |
75 |
is( $job->report->{total_success}, 1 ); |
54 |
|
76 |
|
55 |
$schema->storage->txn_rollback; |
77 |
$schema->storage->txn_rollback; |
56 |
}; |
78 |
}; |
57 |
- |
|
|