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