From 45be637586eb76a9bcbc33e5a3eafa8e481c7ec6 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 1 May 2019 12:56:05 +0100 Subject: [PATCH] Bug 5770: (QA follow-up) Revert change to GetQueuedMessages Signed-off-by: Martin Renvoize --- C4/Letters.pm | 11 +++-------- t/db_dependent/Suggestions.t | 26 ++++++++++---------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 8b086a79ab..bdb213a49e 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1058,10 +1058,10 @@ sub GetPrintMessages { my $messages = GetQueuedMessage( { borrowernumber => '123', limit => 20 } ); -fetches messages out of the message queue. +Fetches a list of messages from the message queue optionally filtered by borrowernumber +and limited to specified limit. -returns: -list of hashes, each has represents a message in the message queue. +Return is an arrayref of hashes, each has represents a message in the message queue. =cut @@ -1081,11 +1081,6 @@ ENDSQL push @query_params, $params->{'borrowernumber'}; } - if ( exists $params->{'letter_code'} ) { - push @whereclauses, ' letter_code = ? '; - push @query_params, $params->{'letter_code'}; - } - if ( @whereclauses ) { $statement .= ' WHERE ' . join( 'AND', @whereclauses ); } diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t index 816786a2f8..02d1d92bec 100644 --- a/t/db_dependent/Suggestions.t +++ b/t/db_dependent/Suggestions.t @@ -42,6 +42,8 @@ $schema->storage->txn_begin; my $dbh = C4::Context->dbh; my $builder = t::lib::TestBuilder->new; +t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "0"); + # Reset item types to only the default ones $dbh->do(q|DELETE FROM itemtypes;|); my $sql = qq| @@ -191,8 +193,7 @@ isnt( $suggestion->{accepteddate}, undef, 'ModSuggestion does not update a non g is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not given' ); my $messages = C4::Letters::GetQueuedMessages({ - borrowernumber => $borrowernumber, - letter_code => 'CHECKED', + borrowernumber => $borrowernumber }); is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' ); @@ -219,8 +220,7 @@ is( $status, 1, 'ModSuggestion modifies one entry' ); $suggestion = GetSuggestion($my_suggestionid); is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' ); $messages = C4::Letters::GetQueuedMessages({ - borrowernumber => $borrowernumber, - letter_code => 'CHECKED', + borrowernumber => $borrowernumber }); is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is disabled the suggestion message_transport_type is always email'); @@ -230,8 +230,7 @@ is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number o t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 ); ModSuggestion($mod_suggestion3); $messages = C4::Letters::GetQueuedMessages({ - borrowernumber => $borrowernumber, - letter_code => 'CHECKED', + borrowernumber => $borrowernumber }); is ($messages->[1]->{message_transport_type}, 'sms', 'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is sms if the borrower has no email'); @@ -246,8 +245,7 @@ my $mod_suggestion4 = { }; ModSuggestion($mod_suggestion4); $messages = C4::Letters::GetQueuedMessages({ - borrowernumber => $borrowernumber2, - letter_code => 'CHECKED', + borrowernumber => $borrowernumber2 }); is ($messages->[0]->{message_transport_type}, 'email', 'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is email if the borrower has an email'); @@ -489,8 +487,7 @@ subtest 'EmailPurchaseSuggestions' => sub { t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress"); NewSuggestion($my_suggestion); my $newsuggestions_messages = C4::Letters::GetQueuedMessages({ - borrowernumber => $borrowernumber, - letter_code => 'NEW_SUGGESTION', + borrowernumber => $borrowernumber }); is( @$newsuggestions_messages, 1, 'NewSuggestions sends an email' ); @@ -500,8 +497,7 @@ subtest 'EmailPurchaseSuggestions' => sub { t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "EmailAddressForSuggestions"); NewSuggestion($my_suggestion); $newsuggestions_messages = C4::Letters::GetQueuedMessages({ - borrowernumber => $borrowernumber, - letter_code => 'NEW_SUGGESTION', + borrowernumber => $borrowernumber }); my $message2 = C4::Letters::GetMessage( $newsuggestions_messages->[1]->{message_id}); is ($message2->{to_address}, 'a@b.c', 'to_address is EmailAddressForSuggestions'); @@ -509,8 +505,7 @@ subtest 'EmailPurchaseSuggestions' => sub { t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "BranchEmailAddress"); NewSuggestion($my_suggestion); $newsuggestions_messages = C4::Letters::GetQueuedMessages({ - borrowernumber => $borrowernumber, - letter_code => 'NEW_SUGGESTION', + borrowernumber => $borrowernumber }); my $message3 = C4::Letters::GetMessage( $newsuggestions_messages->[2]->{message_id}); is ($message3->{to_address}, 'branchemail@b.c', 'to_address is BranchEmailAddress'); @@ -518,8 +513,7 @@ subtest 'EmailPurchaseSuggestions' => sub { Koha::Libraries->find('CPL')->update({ branchemail => undef }); NewSuggestion($my_suggestion); $newsuggestions_messages = C4::Letters::GetQueuedMessages({ - borrowernumber => $borrowernumber, - letter_code => 'NEW_SUGGESTION', + borrowernumber => $borrowernumber }); my $message4 = C4::Letters::GetMessage( $newsuggestions_messages->[3]->{message_id}); isnt ($message4->{to_address}, 'branchemail@b.c', 'to_address is KohaAdminEmailAddress. Because branchemail is undef'); -- 2.20.1