Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 8; |
22 |
use Test::More tests => 10; |
23 |
|
23 |
|
24 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
25 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
Lines 354-356
subtest 'current_item_level_holds() tests' => sub {
Link Here
|
354 |
|
354 |
|
355 |
$schema->storage->txn_rollback; |
355 |
$schema->storage->txn_rollback; |
356 |
}; |
356 |
}; |
357 |
- |
357 |
|
|
|
358 |
subtest 'claim*' => sub { |
359 |
plan tests => 6; |
360 |
|
361 |
$schema->storage->txn_begin; |
362 |
my $order = $builder->build_object( |
363 |
{ |
364 |
class => 'Koha::Acquisition::Orders', |
365 |
} |
366 |
); |
367 |
|
368 |
my $now = dt_from_string; |
369 |
is( $order->claims->count, 0, 'No claim yet, ->claims should return an empty set'); |
370 |
is( $order->claims_count, 0, 'No claim yet, ->claims_count should return 0'); |
371 |
is( $order->claimed_date, undef, 'No claim yet, ->claimed_date should return undef'); |
372 |
|
373 |
my $claim_1 = $order->claim; |
374 |
my $claim_2 = $order->claim; |
375 |
|
376 |
$claim_1->claimed_on($now->clone->subtract(days => 1))->store; |
377 |
|
378 |
is( $order->claims->count, 2, '->claims should return the correct number of claims'); |
379 |
is( $order->claims_count, 2, '->claims_count should return the correct number of claims'); |
380 |
is( dt_from_string($order->claimed_date), $now, '->claimed_date should return the date of the last claim'); |
381 |
|
382 |
$schema->storage->txn_rollback; |
383 |
}; |
384 |
|
385 |
subtest 'filter_by_late' => sub { |
386 |
plan tests => 16; |
387 |
|
388 |
$schema->storage->txn_begin; |
389 |
my $now = dt_from_string; |
390 |
my $bookseller = $builder->build_object( |
391 |
{ |
392 |
class => 'Koha::Acquisition::Booksellers', |
393 |
value => { deliverytime => 2 } |
394 |
} |
395 |
); |
396 |
my $basket_1 = $builder->build_object( |
397 |
{ |
398 |
class => 'Koha::Acquisition::Baskets', |
399 |
value => { |
400 |
booksellerid => $bookseller->id, |
401 |
closedate => undef, |
402 |
} |
403 |
} |
404 |
); |
405 |
my $order_1 = $builder->build_object( |
406 |
{ |
407 |
class => 'Koha::Acquisition::Orders', |
408 |
value => { |
409 |
basketno => $basket_1->basketno, |
410 |
datereceived => undef, |
411 |
datecancellationprinted => undef, |
412 |
} |
413 |
} |
414 |
); |
415 |
my $basket_2 = $builder->build_object( # expected tomorrow |
416 |
{ |
417 |
class => 'Koha::Acquisition::Baskets', |
418 |
value => { |
419 |
booksellerid => $bookseller->id, |
420 |
closedate => $now->clone->subtract( days => 1 ), |
421 |
} |
422 |
} |
423 |
); |
424 |
my $order_2 = $builder->build_object( |
425 |
{ |
426 |
class => 'Koha::Acquisition::Orders', |
427 |
value => { |
428 |
basketno => $basket_2->basketno, |
429 |
datereceived => undef, |
430 |
datecancellationprinted => undef, |
431 |
} |
432 |
} |
433 |
); |
434 |
my $basket_3 = $builder->build_object( # expected yesterday (1 day) |
435 |
{ |
436 |
class => 'Koha::Acquisition::Baskets', |
437 |
value => { |
438 |
booksellerid => $bookseller->id, |
439 |
closedate => $now->clone->subtract( days => 3 ), |
440 |
} |
441 |
} |
442 |
); |
443 |
my $order_3 = $builder->build_object( |
444 |
{ |
445 |
class => 'Koha::Acquisition::Orders', |
446 |
value => { |
447 |
basketno => $basket_3->basketno, |
448 |
datereceived => undef, |
449 |
datecancellationprinted => undef, |
450 |
} |
451 |
} |
452 |
); |
453 |
my $basket_4 = $builder->build_object( # expected 3 days ago |
454 |
{ |
455 |
class => 'Koha::Acquisition::Baskets', |
456 |
value => { |
457 |
booksellerid => $bookseller->id, |
458 |
closedate => $now->clone->subtract( days => 5 ), |
459 |
} |
460 |
} |
461 |
); |
462 |
my $order_4 = $builder->build_object( |
463 |
{ |
464 |
class => 'Koha::Acquisition::Orders', |
465 |
value => { |
466 |
basketno => $basket_4->basketno, |
467 |
datereceived => undef, |
468 |
datecancellationprinted => undef, |
469 |
} |
470 |
} |
471 |
); |
472 |
|
473 |
my $orders = Koha::Acquisition::Orders->search( |
474 |
{ |
475 |
ordernumber => { |
476 |
-in => [ |
477 |
$order_1->ordernumber, $order_2->ordernumber, |
478 |
$order_3->ordernumber, $order_4->ordernumber, |
479 |
] |
480 |
} |
481 |
} |
482 |
); |
483 |
|
484 |
my $late_orders = $orders->filter_by_lates; |
485 |
is( $late_orders->count, 3 ); |
486 |
|
487 |
$late_orders = $orders->filter_by_lates( { delay => 0 } ); |
488 |
is( $late_orders->count, 3 ); |
489 |
|
490 |
$late_orders = $orders->filter_by_lates( { delay => 1 } ); |
491 |
is( $late_orders->count, 3 ); |
492 |
|
493 |
$late_orders = $orders->filter_by_lates( { delay => 3 } ); |
494 |
is( $late_orders->count, 2 ); |
495 |
|
496 |
$late_orders = $orders->filter_by_lates( { delay => 4 } ); |
497 |
is( $late_orders->count, 1 ); |
498 |
|
499 |
$late_orders = $orders->filter_by_lates( { delay => 5 } ); |
500 |
is( $late_orders->count, 1 ); |
501 |
|
502 |
$late_orders = $orders->filter_by_lates( { delay => 6 } ); |
503 |
is( $late_orders->count, 0 ); |
504 |
|
505 |
$late_orders = $orders->filter_by_lates( |
506 |
{ estimated_from => $now->clone->subtract( days => 6 ) } ); |
507 |
is( $late_orders->count, 2 ); |
508 |
is( $late_orders->next->ordernumber, $order_3->ordernumber ); |
509 |
|
510 |
$late_orders = $orders->filter_by_lates( |
511 |
{ estimated_from => $now->clone->subtract( days => 5 ) } ); |
512 |
is( $late_orders->count, 2 ); |
513 |
is( $late_orders->next->ordernumber, $order_3->ordernumber ); |
514 |
|
515 |
$late_orders = $orders->filter_by_lates( |
516 |
{ estimated_from => $now->clone->subtract( days => 4 ) } ); |
517 |
is( $late_orders->count, 2 ); |
518 |
is( $late_orders->next->ordernumber, $order_3->ordernumber ); |
519 |
|
520 |
$late_orders = $orders->filter_by_lates( |
521 |
{ estimated_from => $now->clone->subtract( days => 3 ) } ); |
522 |
is( $late_orders->count, 2 ); |
523 |
|
524 |
$late_orders = $orders->filter_by_lates( |
525 |
{ estimated_from => $now->clone->subtract( days => 1 ) } ); |
526 |
is( $late_orders->count, 1 ); |
527 |
|
528 |
$late_orders = $orders->filter_by_lates( |
529 |
{ |
530 |
estimated_from => $now->clone->subtract( days => 4 ), |
531 |
estimated_to => $now->clone->subtract( days => 3 ) |
532 |
} |
533 |
); |
534 |
is( $late_orders->count, 1 ); |
535 |
|
536 |
$schema->storage->txn_rollback; |
537 |
}; |