|
Lines 25-32
use Koha::Database;
Link Here
|
| 25 |
use Koha::BackgroundJobs; |
25 |
use Koha::BackgroundJobs; |
| 26 |
use Koha::BackgroundJob::BatchUpdateItem; |
26 |
use Koha::BackgroundJob::BatchUpdateItem; |
| 27 |
|
27 |
|
| 28 |
use JSON qw( decode_json encode_json ); |
|
|
| 29 |
|
| 30 |
use t::lib::Mocks; |
28 |
use t::lib::Mocks; |
| 31 |
use t::lib::Mocks::Logger; |
29 |
use t::lib::Mocks::Logger; |
| 32 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
|
Lines 108-114
subtest 'enqueue() tests' => sub {
Link Here
|
| 108 |
is( $job->size, 3, 'Three steps' ); |
106 |
is( $job->size, 3, 'Three steps' ); |
| 109 |
is( $job->status, 'new', 'Initial status set correctly' ); |
107 |
is( $job->status, 'new', 'Initial status set correctly' ); |
| 110 |
is( $job->borrowernumber, $patron->id, 'Borrowernumber set from userenv' ); |
108 |
is( $job->borrowernumber, $patron->id, 'Borrowernumber set from userenv' ); |
| 111 |
is_deeply( decode_json( $job->context ), $job_context, 'Context set from userenv + interface' ); |
109 |
is_deeply( $job->json->decode( $job->context ), $job_context, 'Context set from userenv + interface' ); |
| 112 |
|
110 |
|
| 113 |
$schema->storage->txn_rollback; |
111 |
$schema->storage->txn_rollback; |
| 114 |
}; |
112 |
}; |
|
Lines 150-163
subtest 'start(), step() and finish() tests' => sub {
Link Here
|
| 150 |
|
148 |
|
| 151 |
is( $job->status, 'cancelled', "'finish' leaves 'cancelled' untouched" ); |
149 |
is( $job->status, 'cancelled', "'finish' leaves 'cancelled' untouched" ); |
| 152 |
isnt( $job->ended_on, undef, 'ended_on set' ); |
150 |
isnt( $job->ended_on, undef, 'ended_on set' ); |
| 153 |
is_deeply( decode_json( $job->data ), $data ); |
151 |
is_deeply( $job->json->decode( $job->data ), $data ); |
| 154 |
|
152 |
|
| 155 |
$job->status('started')->store; |
153 |
$job->status('started')->store; |
| 156 |
$job->finish( $data ); |
154 |
$job->finish( $data ); |
| 157 |
|
155 |
|
| 158 |
is( $job->status, 'finished' ); |
156 |
is( $job->status, 'finished' ); |
| 159 |
isnt( $job->ended_on, undef, 'ended_on set' ); |
157 |
isnt( $job->ended_on, undef, 'ended_on set' ); |
| 160 |
is_deeply( decode_json( $job->data ), $data ); |
158 |
is_deeply( $job->json->decode( $job->data ), $data ); |
| 161 |
|
159 |
|
| 162 |
throws_ok |
160 |
throws_ok |
| 163 |
{ $job->start; } |
161 |
{ $job->start; } |
|
Lines 224-238
subtest 'process tests' => sub {
Link Here
|
| 224 |
is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" ); |
222 |
is_deeply( C4::Context->interface, 'intranet', "Interface set from job context on process" ); |
| 225 |
|
223 |
|
| 226 |
# Manually add a job (->new->store) without context |
224 |
# Manually add a job (->new->store) without context |
|
|
225 |
my $json = $job->json; # sorry, quickly borrowing your json object |
| 226 |
my $data = $json->encode({ a => 'a', b => 'b' }); |
| 227 |
my $incomplete_job = t::lib::Koha::BackgroundJob::BatchTest->new( |
227 |
my $incomplete_job = t::lib::Koha::BackgroundJob::BatchTest->new( |
| 228 |
{ status => 'new', |
228 |
{ status => 'new', |
| 229 |
size => 1, |
229 |
size => 1, |
| 230 |
borrowernumber => $patron->borrowernumber, |
230 |
borrowernumber => $patron->borrowernumber, |
| 231 |
type => 'batch_test', |
231 |
type => 'batch_test', |
| 232 |
data => encode_json { |
232 |
data => $data, |
| 233 |
a => 'a', |
|
|
| 234 |
b => 'b', |
| 235 |
}, |
| 236 |
} |
233 |
} |
| 237 |
)->store; |
234 |
)->store; |
| 238 |
|
235 |
|
|
Lines 254-259
subtest 'decoded_data() and set_encoded_data() tests' => sub {
Link Here
|
| 254 |
|
251 |
|
| 255 |
$job->set_encoded_data( $data ); |
252 |
$job->set_encoded_data( $data ); |
| 256 |
|
253 |
|
| 257 |
is_deeply( decode_json($job->data), $data ); |
254 |
is_deeply( $job->json->decode($job->data), $data ); |
| 258 |
is_deeply( $job->decoded_data, $data ); |
255 |
is_deeply( $job->decoded_data, $data ); |
| 259 |
}; |
256 |
}; |