Bugzilla – Attachment 113884 Details for
Bug 26922
SendAlerts does not correctly handle error on sending emails
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26922: Regression tests
Bug-26922-Regression-tests.patch (text/plain), 7.25 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-11-20 14:08:20 UTC
(
hide
)
Description:
Bug 26922: Regression tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-11-20 14:08:20 UTC
Size:
7.25 KB
patch
obsolete
>From dc026acc129d2d47a9983948f148734c473164d0 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 20 Nov 2020 11:04:04 -0300 >Subject: [PATCH] Bug 26922: Regression tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Letters.t | 73 ++++++++++++++++++++++++++++++++++------ > 1 file changed, 62 insertions(+), 11 deletions(-) > >diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t >index 88dfec8b1d7..613f5696d30 100755 >--- a/t/db_dependent/Letters.t >+++ b/t/db_dependent/Letters.t >@@ -18,10 +18,12 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 77; >+use Test::More tests => 83; > use Test::MockModule; > use Test::Warn; > >+use Email::Sender::Failure; >+ > use MARC::Record; > > use utf8; >@@ -461,11 +463,23 @@ t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'library@domain.com' ); > warning_like { > $err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ) } > qr|Fake send_or_die|, >- "SendAlerts is using the mocked sendmail routine (orderacquisition)"; >+ "SendAlerts is using the mocked send_or_die routine (orderacquisition)"; > is($err, 1, "Successfully sent order."); > is($email_object->email->header('To'), 'testemail@mydomain.com', "mailto correct in sent order"); > is($email_object->email->body, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Order notice text constructed successfully'); > >+my $mocked_koha_email = Test::MockModule->new('Koha::Email'); >+$mocked_koha_email->mock( 'send_or_die', sub { >+ Email::Sender::Failure->throw('something went wrong'); >+}); >+ >+warning_like { >+ $err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ); } >+ qr{something went wrong}, >+ 'Warning is printed'; >+ >+is($err->{error}, 'something went wrong', "Send exception, error message returned"); >+ > $dbh->do(q{DELETE FROM letter WHERE code = 'TESTACQORDER';}); > warning_like { > $err = SendAlerts( 'orderacquisition', $basketno , 'TESTACQORDER' ) } >@@ -478,11 +492,23 @@ is($err->{'error'}, 'no_letter', "No TESTACQORDER letter was defined."); > warning_like { > $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) } > qr|Fake send_or_die|, >- "SendAlerts is using the mocked sendmail routine"; >+ "SendAlerts is using the mocked send_or_die routine"; > > is($err, 1, "Successfully sent claim"); > is($email_object->email->header('To'), 'testemail@mydomain.com', "mailto correct in sent claim"); > is($email_object->email->body, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Claim notice text constructed successfully'); >+ >+my $mocked_koha_email = Test::MockModule->new('Koha::Email'); >+$mocked_koha_email->mock( 'send_or_die', sub { >+ Email::Sender::Failure->throw('something went wrong'); >+}); >+ >+warning_like { >+ $err = SendAlerts( 'claimacquisition', [ $ordernumber ] , 'TESTACQCLAIM' ); } >+ qr{something went wrong}, >+ 'Warning is printed'; >+ >+is($err->{error}, 'something went wrong', "Send exception, error message returned"); > } > > { >@@ -520,7 +546,7 @@ my $err2; > warning_like { > $err2 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) } > qr|Fake send_or_die|, >- "SendAlerts is using the mocked sendmail routine"; >+ "SendAlerts is using the mocked send_or_die routine"; > > is($err2, 1, "Successfully sent serial notification"); > is($email_object->email->header('To'), 'john.smith@test.de', "mailto correct in sent serial notification"); >@@ -532,13 +558,26 @@ my $err3; > warning_like { > $err3 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) } > qr|Fake send_or_die|, >- "SendAlerts is using the mocked sendmail routine"; >+ "SendAlerts is using the mocked send_or_die routine"; > is($email_object->email->header('To'), 'robert.tables@mail.com', "mailto address overwritten by SendAllMailsTo preference"); >+ >+my $mocked_koha_email = Test::MockModule->new('Koha::Email'); >+$mocked_koha_email->mock( 'send_or_die', sub { >+ Email::Sender::Failure->throw('something went wrong'); >+}); >+ >+warning_like { >+ $err = SendAlerts( 'issue', $serial->{serialid} , 'RLIST' ); } >+ qr{something went wrong}, >+ 'Warning is printed'; >+ >+is($err->{error}, 'something went wrong', "Send exception, error message returned"); >+ > } > t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' ); > > subtest 'SendAlerts - claimissue' => sub { >- plan tests => 11; >+ plan tests => 13; > > use C4::Serials; > >@@ -605,7 +644,7 @@ subtest 'SendAlerts - claimissue' => sub { > warning_like { > $err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' ) } > qr|Fake send_or_die|, >- "SendAlerts is using the mocked sendmail routine (claimissues)"; >+ "SendAlerts is using the mocked send_or_die routine (claimissues)"; > is( $err, 1, "Successfully sent claim" ); > is( $email_object->email->header('To'), > 'testemail@mydomain.com', "mailto correct in sent claim" ); >@@ -614,6 +653,18 @@ subtest 'SendAlerts - claimissue' => sub { > "$serialids[0]|2013-01-01|Silence in the library|xxxx-yyyy", > 'Serial claim letter for 1 issue constructed successfully' > ); >+ >+ my $mocked_koha_email = Test::MockModule->new('Koha::Email'); >+ $mocked_koha_email->mock( 'send_or_die', sub { >+ Email::Sender::Failure->throw('something went wrong'); >+ }); >+ >+ warning_like { >+ $err = SendAlerts( 'claimissues', \@serialids , 'TESTSERIALCLAIM' ); } >+ qr{something went wrong}, >+ 'Warning is printed'; >+ >+ is($err->{error}, 'something went wrong', "Send exception, error message returned"); > } > > { >@@ -625,7 +676,7 @@ subtest 'SendAlerts - claimissue' => sub { > > warning_like { $err = SendAlerts( 'claimissues', \@serialids, 'TESTSERIALCLAIM' ); } > qr|Fake send_or_die|, >- "SendAlerts is using the mocked sendmail routine (claimissues)"; >+ "SendAlerts is using the mocked send_or_die routine (claimissues)"; > > is( > $email_object->email->body, >@@ -773,7 +824,7 @@ subtest 'SendQueuedMessages' => sub { > > warning_like { C4::Letters::SendQueuedMessages(); } > qr|Fake send_or_die|, >- "SendAlerts is using the mocked sendmail routine (claimissues)"; >+ "SendAlerts is using the mocked send_or_die routine (claimissues)"; > > my $message = $schema->resultset('MessageQueue')->search({ > borrowernumber => $borrowernumber, >@@ -794,7 +845,7 @@ subtest 'SendQueuedMessages' => sub { > $message_id = C4::Letters::EnqueueLetter($my_message); > warning_like { C4::Letters::SendQueuedMessages(); } > qr|Fake send_or_die|, >- "SendAlerts is using the mocked sendmail routine (claimissues)"; >+ "SendAlerts is using the mocked send_or_die routine (claimissues)"; > > $message = $schema->resultset('MessageQueue')->search({ > borrowernumber => $borrowernumber, >@@ -819,7 +870,7 @@ subtest 'SendQueuedMessages' => sub { > > warning_like { C4::Letters::SendQueuedMessages(); } > qr|Fake send_or_die|, >- "SendAlerts is using the mocked sendmail routine (claimissues)"; >+ "SendAlerts is using the mocked send_or_die routine (claimissues)"; > > my $sms_message_address = $schema->resultset('MessageQueue')->search({ > borrowernumber => $borrowernumber, >-- >2.29.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26922
:
113736
|
113828
|
113849
|
113870
|
113884
|
113894
|
113895