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