Lines 19-30
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 8; |
23 |
|
23 |
|
24 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
25 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
26 |
|
26 |
|
27 |
use Koha::Database; |
27 |
use Koha::Database; |
|
|
28 |
use Koha::DateUtils qw( dt_from_string ); |
28 |
|
29 |
|
29 |
my $schema = Koha::Database->schema; |
30 |
my $schema = Koha::Database->schema; |
30 |
my $builder = t::lib::TestBuilder->new; |
31 |
my $builder = t::lib::TestBuilder->new; |
Lines 250-252
subtest 'duplicate_to | add_item' => sub {
Link Here
|
250 |
|
251 |
|
251 |
$schema->storage->txn_rollback; |
252 |
$schema->storage->txn_rollback; |
252 |
}; |
253 |
}; |
253 |
- |
254 |
|
|
|
255 |
subtest 'claim*' => sub { |
256 |
plan tests => 6; |
257 |
|
258 |
$schema->storage->txn_begin; |
259 |
my $order = $builder->build_object( |
260 |
{ |
261 |
class => 'Koha::Acquisition::Orders', |
262 |
} |
263 |
); |
264 |
|
265 |
my $now = dt_from_string; |
266 |
is( $order->claims->count, 0, 'No claim yet, ->claims should return an empty set'); |
267 |
is( $order->claims_count, 0, 'No claim yet, ->claims_count should return 0'); |
268 |
is( $order->claimed_date, undef, 'No claim yet, ->claimed_date should return undef'); |
269 |
|
270 |
my $claim_1 = $order->claim; |
271 |
my $claim_2 = $order->claim; |
272 |
|
273 |
$claim_1->claimed_on($now->clone->subtract(days => 1))->store; |
274 |
|
275 |
is( $order->claims->count, 2, '->claims should return the correct number of claims'); |
276 |
is( $order->claims_count, 2, '->claims_count should return the correct number of claims'); |
277 |
is( dt_from_string($order->claimed_date), $now, '->claimed_date should return the date of the last claim'); |
278 |
|
279 |
$schema->storage->txn_rollback; |
280 |
}; |
281 |
|
282 |
subtest 'filter_by_late' => sub { |
283 |
plan tests => 16; |
284 |
|
285 |
$schema->storage->txn_begin; |
286 |
my $now = dt_from_string; |
287 |
my $bookseller = $builder->build_object( |
288 |
{ |
289 |
class => 'Koha::Acquisition::Booksellers', |
290 |
value => { deliverytime => 2 } |
291 |
} |
292 |
); |
293 |
my $basket_1 = $builder->build_object( |
294 |
{ |
295 |
class => 'Koha::Acquisition::Baskets', |
296 |
value => { |
297 |
booksellerid => $bookseller->id, |
298 |
closedate => undef, |
299 |
} |
300 |
} |
301 |
); |
302 |
my $order_1 = $builder->build_object( |
303 |
{ |
304 |
class => 'Koha::Acquisition::Orders', |
305 |
value => { |
306 |
basketno => $basket_1->basketno, |
307 |
datereceived => undef, |
308 |
datecancellationprinted => undef, |
309 |
} |
310 |
} |
311 |
); |
312 |
my $basket_2 = $builder->build_object( # expected tomorrow |
313 |
{ |
314 |
class => 'Koha::Acquisition::Baskets', |
315 |
value => { |
316 |
booksellerid => $bookseller->id, |
317 |
closedate => $now->clone->subtract( days => 1 ), |
318 |
} |
319 |
} |
320 |
); |
321 |
my $order_2 = $builder->build_object( |
322 |
{ |
323 |
class => 'Koha::Acquisition::Orders', |
324 |
value => { |
325 |
basketno => $basket_2->basketno, |
326 |
datereceived => undef, |
327 |
datecancellationprinted => undef, |
328 |
} |
329 |
} |
330 |
); |
331 |
my $basket_3 = $builder->build_object( # expected yesterday (1 day) |
332 |
{ |
333 |
class => 'Koha::Acquisition::Baskets', |
334 |
value => { |
335 |
booksellerid => $bookseller->id, |
336 |
closedate => $now->clone->subtract( days => 3 ), |
337 |
} |
338 |
} |
339 |
); |
340 |
my $order_3 = $builder->build_object( |
341 |
{ |
342 |
class => 'Koha::Acquisition::Orders', |
343 |
value => { |
344 |
basketno => $basket_3->basketno, |
345 |
datereceived => undef, |
346 |
datecancellationprinted => undef, |
347 |
} |
348 |
} |
349 |
); |
350 |
my $basket_4 = $builder->build_object( # expected 3 days ago |
351 |
{ |
352 |
class => 'Koha::Acquisition::Baskets', |
353 |
value => { |
354 |
booksellerid => $bookseller->id, |
355 |
closedate => $now->clone->subtract( days => 5 ), |
356 |
} |
357 |
} |
358 |
); |
359 |
my $order_4 = $builder->build_object( |
360 |
{ |
361 |
class => 'Koha::Acquisition::Orders', |
362 |
value => { |
363 |
basketno => $basket_4->basketno, |
364 |
datereceived => undef, |
365 |
datecancellationprinted => undef, |
366 |
} |
367 |
} |
368 |
); |
369 |
|
370 |
my $orders = Koha::Acquisition::Orders->search( |
371 |
{ |
372 |
ordernumber => { |
373 |
-in => [ |
374 |
$order_1->ordernumber, $order_2->ordernumber, |
375 |
$order_3->ordernumber, $order_4->ordernumber, |
376 |
] |
377 |
} |
378 |
} |
379 |
); |
380 |
|
381 |
my $late_orders = $orders->filter_by_lates; |
382 |
is( $late_orders->count, 3 ); |
383 |
|
384 |
$late_orders = $orders->filter_by_lates( { delay => 0 } ); |
385 |
is( $late_orders->count, 3 ); |
386 |
|
387 |
$late_orders = $orders->filter_by_lates( { delay => 1 } ); |
388 |
is( $late_orders->count, 3 ); |
389 |
|
390 |
$late_orders = $orders->filter_by_lates( { delay => 3 } ); |
391 |
is( $late_orders->count, 2 ); |
392 |
|
393 |
$late_orders = $orders->filter_by_lates( { delay => 4 } ); |
394 |
is( $late_orders->count, 1 ); |
395 |
|
396 |
$late_orders = $orders->filter_by_lates( { delay => 5 } ); |
397 |
is( $late_orders->count, 1 ); |
398 |
|
399 |
$late_orders = $orders->filter_by_lates( { delay => 6 } ); |
400 |
is( $late_orders->count, 0 ); |
401 |
|
402 |
$late_orders = $orders->filter_by_lates( |
403 |
{ estimated_from => $now->clone->subtract( days => 6 ) } ); |
404 |
is( $late_orders->count, 2 ); |
405 |
is( $late_orders->next->ordernumber, $order_3->ordernumber ); |
406 |
|
407 |
$late_orders = $orders->filter_by_lates( |
408 |
{ estimated_from => $now->clone->subtract( days => 5 ) } ); |
409 |
is( $late_orders->count, 2 ); |
410 |
is( $late_orders->next->ordernumber, $order_3->ordernumber ); |
411 |
|
412 |
$late_orders = $orders->filter_by_lates( |
413 |
{ estimated_from => $now->clone->subtract( days => 4 ) } ); |
414 |
is( $late_orders->count, 2 ); |
415 |
is( $late_orders->next->ordernumber, $order_3->ordernumber ); |
416 |
|
417 |
$late_orders = $orders->filter_by_lates( |
418 |
{ estimated_from => $now->clone->subtract( days => 3 ) } ); |
419 |
is( $late_orders->count, 2 ); |
420 |
|
421 |
$late_orders = $orders->filter_by_lates( |
422 |
{ estimated_from => $now->clone->subtract( days => 1 ) } ); |
423 |
is( $late_orders->count, 1 ); |
424 |
|
425 |
$late_orders = $orders->filter_by_lates( |
426 |
{ |
427 |
estimated_from => $now->clone->subtract( days => 4 ), |
428 |
estimated_to => $now->clone->subtract( days => 3 ) |
429 |
} |
430 |
); |
431 |
is( $late_orders->count, 1 ); |
432 |
|
433 |
$schema->storage->txn_rollback; |
434 |
}; |