Bug 28803: Add unit tests

This patch updates Letters.t to confirm that invalid email addresses in
the message_queue should not throw an exception when sending mail but
instead set the status to failed and pass error details to the end user.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Martin Renvoize 2021-08-05 08:43:32 +01:00 committed by Fridolin Somers
parent 1c768b1c99
commit 2712dbeca6
1 changed files with 4 additions and 7 deletions

View File

@ -990,13 +990,10 @@ subtest 'Test message_id parameter for SendQueuedMessages' => sub {
'from_address' => '@example.com' # invalid KohaAdminEmailAddress
};
my $message_id = C4::Letters::EnqueueLetter($my_message);
throws_ok {
C4::Letters::SendQueuedMessages( { message_id => $message_id } );
} 'Koha::Exceptions::BadParameter',
'Exception thrown if invalid email is passed';
my $processed = C4::Letters::SendQueuedMessages( { message_id => $message_id } );
is( $processed, 1, 'Processed 1 message when one message_id passed' );
my $message_1 = C4::Letters::GetMessage($message_id);
# FIXME must be 'failed'
is( $message_1->{status}, 'pending', 'Invalid KohaAdminEmailAddress => status pending' );
is( $message_1->{status}, 'failed', 'Invalid KohaAdminEmailAddress => status failed' );
$my_message->{from_address} = 'root@example.org'; # valid KohaAdminEmailAddress
$message_id = C4::Letters::EnqueueLetter($my_message);
@ -1005,6 +1002,6 @@ subtest 'Test message_id parameter for SendQueuedMessages' => sub {
"SendQueuedMessages is using the mocked send_or_die routine";
$message_1 = C4::Letters::GetMessage($message_1->{message_id});
my $message_2 = C4::Letters::GetMessage($message_id);
is( $message_1->{status}, 'pending', 'Message 1 status is unchanged' ); # Must be 'failed'
is( $message_1->{status}, 'failed', 'Message 1 status is unchanged' );
is( $message_2->{status}, 'sent', 'Valid KohaAdminEmailAddress => status sent' );
};