Bug 30889: Unit tests
This patch adds a unit test for the 'enqueue' part of the bug. We check that the mocked context (and interface) are recorded with the job enqueue in the new 'context' field. We do not yet test the 'process' end, where we then read the context out and set the job Context from it. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
c1fcf3510e
commit
defcdd85a4
2 changed files with 22 additions and 3 deletions
|
@ -65,7 +65,7 @@ subtest '_derived_class() tests' => sub {
|
|||
|
||||
subtest 'enqueue() tests' => sub {
|
||||
|
||||
plan tests => 6;
|
||||
plan tests => 7;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
@ -77,15 +77,34 @@ subtest 'enqueue() tests' => sub {
|
|||
is( $job->status, 'new', 'Initial status set correctly' );
|
||||
is( $job->borrowernumber, undef, 'No userenv, borrowernumber undef' );
|
||||
|
||||
my $interface = C4::Context->interface;
|
||||
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
|
||||
t::lib::Mocks::mock_userenv( { patron => $patron } );
|
||||
my $job_context = {
|
||||
number => $patron->borrowernumber,
|
||||
id => $patron->userid,
|
||||
cardnumber => $patron->cardnumber,
|
||||
firstname => $patron->firstname,
|
||||
surname => $patron->surname,
|
||||
branch => $patron->library->branchcode,
|
||||
branchname => $patron->library->branchname,
|
||||
flags => $patron->flags,
|
||||
emailaddress => $patron->email,
|
||||
register_id => undef,
|
||||
register_name => undef,
|
||||
shibboleth => undef,
|
||||
desk_id => undef,
|
||||
desk_name => undef,
|
||||
interface => $interface
|
||||
};
|
||||
|
||||
$job_id = Koha::BackgroundJob::BatchUpdateItem->new->enqueue( { record_ids => [ 1, 2, 3 ] } );
|
||||
$job = Koha::BackgroundJobs->find($job_id)->_derived_class;
|
||||
|
||||
is( $job->size, 3, 'Three steps' );
|
||||
is( $job->status, 'new', 'Initial status set correctly' );
|
||||
is( $job->borrowernumber, $patron->id, 'No userenv, borrowernumber undef' );
|
||||
is( $job->borrowernumber, $patron->id, 'Borrowernumber set from userenv' );
|
||||
is_deeply( decode_json( $job->context ), $job_context, 'Context set from userenv + interface' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
@ -131,7 +131,7 @@ sub mock_userenv {
|
|||
my $branchcode = $params->{branchcode} || $userenv->{branchcode} || 'Branch4T';
|
||||
my $branchname = $params->{branchname} || $userenv->{branchname};
|
||||
my $flags = $params->{flags} || $userenv->{flags} || 0;
|
||||
my $emailaddress = $params->{emailaddress} || $userenv->{emailaddress};
|
||||
my $emailaddress = $params->{emailaddress} || $userenv->{email};
|
||||
my $desk_id = $params->{desk_id} || $userenv->{desk_id};
|
||||
my $desk_name = $params->{desk_name} || $userenv->{desk_name};
|
||||
my $register_id = $params->{register_id} || $userenv->{register_id};
|
||||
|
|
Loading…
Reference in a new issue