|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 69; |
20 |
use Test::More tests => 70; |
| 21 |
use Test::NoWarnings; |
21 |
use Test::NoWarnings; |
| 22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
| 23 |
use Test::Warn; |
23 |
use Test::Warn; |
|
Lines 1466-1471
subtest 'ModReserveAffect logging' => sub {
Link Here
|
| 1466 |
like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); |
1466 |
like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); |
| 1467 |
}; |
1467 |
}; |
| 1468 |
|
1468 |
|
|
|
1469 |
subtest 'ModReserveAffect delayed notice' => sub { |
| 1470 |
|
| 1471 |
plan tests => 4; |
| 1472 |
|
| 1473 |
my $wants_hold_and_email = { |
| 1474 |
wants_digest => '0', |
| 1475 |
transports => { |
| 1476 |
email => 'HOLD', |
| 1477 |
}, |
| 1478 |
letter_code => 'HOLD' |
| 1479 |
}; |
| 1480 |
|
| 1481 |
my $mp = Test::MockModule->new('C4::Members::Messaging'); |
| 1482 |
|
| 1483 |
$mp->mock( "GetMessagingPreferences", $wants_hold_and_email ); |
| 1484 |
|
| 1485 |
$dbh->do('DELETE FROM letter'); |
| 1486 |
$dbh->do('DELETE FROM reserves'); |
| 1487 |
$dbh->do('DELETE FROM message_queue'); |
| 1488 |
|
| 1489 |
my $email_hold_notice = $builder->build( |
| 1490 |
{ |
| 1491 |
source => 'Letter', |
| 1492 |
value => { |
| 1493 |
message_transport_type => 'email', |
| 1494 |
branchcode => '', |
| 1495 |
code => 'HOLD', |
| 1496 |
module => 'reserves', |
| 1497 |
lang => 'default', |
| 1498 |
} |
| 1499 |
} |
| 1500 |
); |
| 1501 |
|
| 1502 |
my $hold_borrower = $builder->build( |
| 1503 |
{ |
| 1504 |
source => 'Borrower', |
| 1505 |
value => { |
| 1506 |
email => 'ac@b.com', |
| 1507 |
} |
| 1508 |
} |
| 1509 |
)->{borrowernumber}; |
| 1510 |
|
| 1511 |
my $hold = C4::Reserves::AddReserve( |
| 1512 |
{ |
| 1513 |
branchcode => $item->homebranch, |
| 1514 |
borrowernumber => $hold_borrower, |
| 1515 |
biblionumber => $item->biblionumber, |
| 1516 |
} |
| 1517 |
); |
| 1518 |
t::lib::Mocks::mock_preference( 'PickupNoticeDelayMode', 'off' ); |
| 1519 |
t::lib::Mocks::mock_preference( 'PickupNoticeDelayDuration', 1 ); |
| 1520 |
|
| 1521 |
# No delay allowed |
| 1522 |
my $tomorrow = dt_from_string()->add( days => 1 ); |
| 1523 |
ModReserveAffect( $item->itemnumber, $hold_borrower, 0, $hold, undef, undef, $tomorrow ); |
| 1524 |
my $delay_until = $schema->resultset('MessageQueue')->search( |
| 1525 |
{ |
| 1526 |
letter_code => 'HOLD', |
| 1527 |
message_transport_type => 'email', |
| 1528 |
borrowernumber => $hold_borrower, |
| 1529 |
}, |
| 1530 |
{ order_by => { -desc => 'message_id' } } |
| 1531 |
)->next()->delay_until(); |
| 1532 |
is( $delay_until, undef, "No notice delay if PickupNoticeDelayMode is off even if delay is passed" ); |
| 1533 |
|
| 1534 |
$dbh->do('DELETE FROM message_queue'); |
| 1535 |
$dbh->do('DELETE FROM reserves'); |
| 1536 |
$hold = C4::Reserves::AddReserve( |
| 1537 |
{ |
| 1538 |
branchcode => $item->homebranch, |
| 1539 |
borrowernumber => $hold_borrower, |
| 1540 |
biblionumber => $item->biblionumber, |
| 1541 |
} |
| 1542 |
); |
| 1543 |
|
| 1544 |
t::lib::Mocks::mock_preference( 'PickupNoticeDelayMode', 'fixed' ); |
| 1545 |
my $more_than_hour = dt_from_string()->add( minutes => 61 ); |
| 1546 |
my $less_than_hour = dt_from_string()->add( minutes => 59 ); |
| 1547 |
ModReserveAffect( $item->itemnumber, $hold_borrower, 0, $hold, undef, undef, undef ); |
| 1548 |
$delay_until = $schema->resultset('MessageQueue')->search( |
| 1549 |
{ |
| 1550 |
letter_code => 'HOLD', |
| 1551 |
message_transport_type => 'email', |
| 1552 |
borrowernumber => $hold_borrower, |
| 1553 |
}, |
| 1554 |
{ order_by => { -desc => 'message_id' } } |
| 1555 |
)->next()->delay_until(); |
| 1556 |
cmp_ok( |
| 1557 |
dt_from_string($delay_until)->epoch, ">=", $less_than_hour->epoch, |
| 1558 |
"1h fixed delay_until is bigger than 59 min." |
| 1559 |
); |
| 1560 |
cmp_ok( dt_from_string($delay_until), "<=", $more_than_hour, "1h fixed delay_until is less than 61 min." ); |
| 1561 |
|
| 1562 |
$dbh->do('DELETE FROM message_queue'); |
| 1563 |
$dbh->do('DELETE FROM reserves'); |
| 1564 |
$hold = C4::Reserves::AddReserve( |
| 1565 |
{ |
| 1566 |
branchcode => $item->homebranch, |
| 1567 |
borrowernumber => $hold_borrower, |
| 1568 |
biblionumber => $item->biblionumber, |
| 1569 |
} |
| 1570 |
); |
| 1571 |
|
| 1572 |
t::lib::Mocks::mock_preference( 'PickupNoticeDelayMode', 'staff' ); |
| 1573 |
ModReserveAffect( $item->itemnumber, $hold_borrower, 0, $hold, undef, undef, $tomorrow ); |
| 1574 |
$delay_until = $schema->resultset('MessageQueue')->search( |
| 1575 |
{ |
| 1576 |
letter_code => 'HOLD', |
| 1577 |
message_transport_type => 'email', |
| 1578 |
borrowernumber => $hold_borrower, |
| 1579 |
}, |
| 1580 |
{ order_by => { -desc => 'message_id' } } |
| 1581 |
)->next()->delay_until(); |
| 1582 |
is( dt_from_string($delay_until), $tomorrow, "Delay_until is same as set in function call" ); |
| 1583 |
}; |
| 1584 |
|
| 1469 |
sub count_hold_print_messages { |
1585 |
sub count_hold_print_messages { |
| 1470 |
my $message_count = $dbh->selectall_arrayref( |
1586 |
my $message_count = $dbh->selectall_arrayref( |
| 1471 |
q{ |
1587 |
q{ |
| 1472 |
- |
|
|