Lines 21-26
use Test::More tests => 2;
Link Here
|
21 |
use Test::Exception; |
21 |
use Test::Exception; |
22 |
|
22 |
|
23 |
use Koha::Database; |
23 |
use Koha::Database; |
|
|
24 |
use Koha::DateUtils qw(dt_from_string); |
24 |
use Koha::BackgroundJobs; |
25 |
use Koha::BackgroundJobs; |
25 |
use Koha::BackgroundJob::PseudonymizeStatistic; |
26 |
use Koha::BackgroundJob::PseudonymizeStatistic; |
26 |
|
27 |
|
Lines 29-34
use t::lib::TestBuilder;
Link Here
|
29 |
|
30 |
|
30 |
my $schema = Koha::Database->new->schema; |
31 |
my $schema = Koha::Database->new->schema; |
31 |
my $builder = t::lib::TestBuilder->new; |
32 |
my $builder = t::lib::TestBuilder->new; |
|
|
33 |
my $dtf = $schema->storage->datetime_parser; |
32 |
|
34 |
|
33 |
subtest 'enqueue() tests' => sub { |
35 |
subtest 'enqueue() tests' => sub { |
34 |
|
36 |
|
Lines 65-93
subtest 'enqueue() tests' => sub {
Link Here
|
65 |
|
67 |
|
66 |
subtest 'process() tests' => sub { |
68 |
subtest 'process() tests' => sub { |
67 |
|
69 |
|
68 |
plan tests => 2; |
70 |
plan tests => 3; |
69 |
|
71 |
|
70 |
$schema->storage->txn_begin; |
72 |
$schema->storage->txn_begin; |
71 |
|
73 |
|
72 |
t::lib::Mocks::mock_config( 'bcrypt_settings', '$2a$08$9lmorEKnwQloheaCLFIfje' ); |
74 |
t::lib::Mocks::mock_config( 'bcrypt_settings', '$2a$08$9lmorEKnwQloheaCLFIfje' ); |
73 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); |
75 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); |
74 |
t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', 'branchcode,categorycode,sort1' ); |
76 |
t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', 'branchcode,categorycode,sort1' ); |
|
|
77 |
t::lib::Mocks::mock_preference( 'PseudonymizationTransactionFields', 'datetime' ); |
75 |
|
78 |
|
76 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
79 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
77 |
my $item = $builder->build_sample_item(); |
80 |
my $item = $builder->build_sample_item(); |
78 |
my $statistic = $builder->build_object( |
81 |
my $statistic = $builder->build_object( |
79 |
{ |
82 |
{ |
80 |
class => 'Koha::Statistics', |
83 |
class => 'Koha::Statistics', |
81 |
value => { type => 'issue', borrowernumber => $patron->id, itemnumber => $item->id } |
84 |
value => { |
|
|
85 |
borrowernumber => $patron->id, |
86 |
datetime => $dtf->format_datetime( dt_from_string()->subtract( days => 7 ) ), |
87 |
itemnumber => $item->id, |
88 |
type => 'issue', |
89 |
} |
82 |
} |
90 |
} |
83 |
); |
91 |
)->unblessed; |
84 |
|
92 |
|
85 |
my $job_id = Koha::BackgroundJob::PseudonymizeStatistic->new->enqueue( { statistic => $statistic->unblessed } ); |
93 |
my $job_id = Koha::BackgroundJob::PseudonymizeStatistic->new->enqueue( { statistic => $statistic } ); |
86 |
my $pseudonymized_transactions_before = Koha::PseudonymizedTransactions->search()->count(); |
94 |
my $pt_count_before = Koha::PseudonymizedTransactions->search()->count(); |
87 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
95 |
|
88 |
$job->process( { statistic => $statistic->unblessed } ); |
96 |
my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; |
89 |
my $pseudonymized_transactions_after = Koha::PseudonymizedTransactions->search()->count(); |
97 |
$job->process( { statistic => $statistic } ); |
90 |
is( $pseudonymized_transactions_after, $pseudonymized_transactions_before + 1, "Pseudonymized transaction added" ); |
98 |
|
|
|
99 |
my $pt_after = Koha::PseudonymizedTransactions->search(); |
100 |
is( $pt_after->count, $pt_count_before + 1, "Pseudonymized transaction added" ); |
101 |
|
102 |
is( $statistic->{datetime}, $pt_after->last->datetime, "'datetime' column preserved" ); |
91 |
|
103 |
|
92 |
$job->discard_changes; |
104 |
$job->discard_changes; |
93 |
is( $job->data, '{"data":""}', "Job data cleared after pseudonymization" ); |
105 |
is( $job->data, '{"data":""}', "Job data cleared after pseudonymization" ); |