Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 16; |
22 |
use Test::More tests => 14; |
23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
24 |
|
24 |
|
25 |
use List::MoreUtils qw(any); |
25 |
use List::MoreUtils qw(any); |
Lines 123-186
subtest 'filter_by_current() tests' => sub {
Link Here
|
123 |
$schema->storage->txn_rollback; |
123 |
$schema->storage->txn_rollback; |
124 |
}; |
124 |
}; |
125 |
|
125 |
|
126 |
subtest 'filter_by_last_hour() tests' => sub { |
|
|
127 |
|
128 |
plan tests => 2; |
129 |
|
130 |
$schema->storage->txn_begin; |
131 |
|
132 |
my $job_now = |
133 |
$builder->build_object( { class => 'Koha::BackgroundJobs', value => { enqueued_on => dt_from_string } } ); |
134 |
my $job_old = $builder->build_object( |
135 |
{ class => 'Koha::BackgroundJobs', value => { enqueued_on => dt_from_string->subtract( hours => 2 ) } } ); |
136 |
my $rs = Koha::BackgroundJobs->search( { id => [ $job_now->id, $job_old->id ] } ); |
137 |
|
138 |
is( $rs->count, 2, '2 jobs in resultset' ); |
139 |
|
140 |
$rs = $rs->filter_by_last_hour; |
141 |
|
142 |
is( $rs->count, 1, 'Only 1 job in filtered resultset' ); |
143 |
|
144 |
$schema->storage->txn_rollback; |
145 |
}; |
146 |
|
147 |
subtest 'filter_by_last_hour() and filter_by_current() tests' => sub { |
148 |
|
149 |
plan tests => 3; |
150 |
|
151 |
$schema->storage->txn_begin; |
152 |
|
153 |
my $job_new_now = $builder->build_object( |
154 |
{ class => 'Koha::BackgroundJobs', value => { status => 'new', enqueued_on => dt_from_string } } ); |
155 |
my $job_new_old = $builder->build_object( |
156 |
{ |
157 |
class => 'Koha::BackgroundJobs', |
158 |
value => { status => 'new', enqueued_on => dt_from_string->subtract( hours => 2 ) } |
159 |
} |
160 |
); |
161 |
my $job_cancelled = $builder->build_object( |
162 |
{ class => 'Koha::BackgroundJobs', value => { status => 'cancelled', enqueued_on => dt_from_string } } ); |
163 |
my $job_failed = $builder->build_object( |
164 |
{ class => 'Koha::BackgroundJobs', value => { status => 'failed', enqueued_on => dt_from_string } } ); |
165 |
my $job_finished = $builder->build_object( |
166 |
{ class => 'Koha::BackgroundJobs', value => { status => 'finished', enqueued_on => dt_from_string } } ); |
167 |
|
168 |
my $rs = Koha::BackgroundJobs->search( |
169 |
{ id => [ $job_new_now->id, $job_new_old->id, $job_cancelled->id, $job_failed->id, $job_finished->id ] } ); |
170 |
|
171 |
is( $rs->count, 5, '5 jobs in resultset' ); |
172 |
|
173 |
$rs = $rs->filter_by_last_hour; |
174 |
|
175 |
is( $rs->count, 4, '4 jobs in last hour' ); |
176 |
|
177 |
$rs = $rs->filter_by_current; |
178 |
|
179 |
is( $rs->count, 1, 'Only 1 current job in last hour' ); |
180 |
|
181 |
$schema->storage->txn_rollback; |
182 |
}; |
183 |
|
184 |
subtest 'search_limited' => sub { |
126 |
subtest 'search_limited' => sub { |
185 |
plan tests => 3; |
127 |
plan tests => 3; |
186 |
|
128 |
|
187 |
- |
|
|