View | Details | Raw Unified | Return to bug 27208
Collapse All | Expand All

(-)a/t/db_dependent/Letters.t (-2 / +32 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 83;
21
use Test::More tests => 88;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
use Test::Exception;
Lines 147-152 is( $messages->[0]->{status}, 'pending', 'EnqueueLetter stores the status pendin Link Here
147
isnt( $messages->[0]->{time_queued}, undef, 'Time queued inserted by default in message_queue table' );
147
isnt( $messages->[0]->{time_queued}, undef, 'Time queued inserted by default in message_queue table' );
148
is( $messages->[0]->{updated_on}, $messages->[0]->{time_queued}, 'Time status changed equals time queued when created in message_queue table' );
148
is( $messages->[0]->{updated_on}, $messages->[0]->{time_queued}, 'Time status changed equals time queued when created in message_queue table' );
149
is( $messages->[0]->{failure_code}, '', 'Failure code for successful message correctly empty');
149
is( $messages->[0]->{failure_code}, '', 'Failure code for successful message correctly empty');
150
is( $messages->[0]->{delay_until}, undef, 'Delay until should be undef if not set');
150
151
151
# Setting time_queued to something else than now
152
# Setting time_queued to something else than now
152
my $yesterday = dt_from_string->subtract( days => 1 );
153
my $yesterday = dt_from_string->subtract( days => 1 );
Lines 171-176 is( Link Here
171
isnt($messages->[0]->{updated_on}, $messages->[0]->{time_queued}, 'Time status changed differs from time queued when status changes' );
172
isnt($messages->[0]->{updated_on}, $messages->[0]->{time_queued}, 'Time status changed differs from time queued when status changes' );
172
is(dt_from_string($messages->[0]->{time_queued}), $yesterday, 'Time queued remaines inmutable' );
173
is(dt_from_string($messages->[0]->{time_queued}), $yesterday, 'Time queued remaines inmutable' );
173
174
175
# Delayed message
176
my $tomorrow = dt_from_string()->add( days => 1 );
177
my $delay_message = {
178
    borrowernumber         => $borrowernumber,
179
    message_transport_type => 'email',
180
    to_address             => 'to@example',
181
    from_address           => 'from@example.com',
182
    delay_until            => $tomorrow,
183
};
184
$delay_message->{letter} = {
185
    content      => 'I am waiting',
186
    title        => 'Patience is great',
187
    metadata     => 'metadata',
188
    code         => 'TEST_MESSAGE',
189
    content_type => 'text/plain',
190
};
191
192
my $delayed_message_id = C4::Letters::EnqueueLetter($delay_message);
193
194
my $delay_until = Koha::Notice::Messages->find($delayed_message_id)->delay_until;
195
is(dt_from_string($delay_until), $tomorrow, 'Delay_until is properly set');
196
197
my $delayed_messages_processed = C4::Letters::SendQueuedMessages();
198
is($delayed_messages_processed, 0, 'Message not processed if delay_until is set in the future');
199
200
Koha::Notice::Messages->find($delayed_message_id)->delay_until($yesterday)->store;
201
$delayed_messages_processed = C4::Letters::SendQueuedMessages();
202
is($delayed_messages_processed, 1, 'Message processed if delay_until is set in the past');
203
Koha::Notice::Messages->find($delayed_message_id)->delete;
204
174
# ResendMessage
205
# ResendMessage
175
my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
206
my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
176
my $message = C4::Letters::GetMessage( $messages->[0]->{message_id});
207
my $message = C4::Letters::GetMessage( $messages->[0]->{message_id});
177
- 

Return to bug 27208