|
Lines 50-56
my $new_suggestion_2 = Koha::Suggestion->new(
Link Here
|
| 50 |
)->store; |
50 |
)->store; |
| 51 |
|
51 |
|
| 52 |
subtest 'store' => sub { |
52 |
subtest 'store' => sub { |
| 53 |
plan tests => 8; |
53 |
plan tests => 9; |
| 54 |
my $suggestion = Koha::Suggestion->new( |
54 |
my $suggestion = Koha::Suggestion->new( |
| 55 |
{ suggestedby => $patron->{borrowernumber}, |
55 |
{ suggestedby => $patron->{borrowernumber}, |
| 56 |
biblionumber => $biblio_1->biblionumber, |
56 |
biblionumber => $biblio_1->biblionumber, |
|
Lines 69-105
subtest 'store' => sub {
Link Here
|
| 69 |
|
69 |
|
| 70 |
t::lib::Mocks::mock_preference( 'EmailPurchaseSuggestions', 0 ); |
70 |
t::lib::Mocks::mock_preference( 'EmailPurchaseSuggestions', 0 ); |
| 71 |
Koha::Notice::Messages->search->delete; |
71 |
Koha::Notice::Messages->search->delete; |
|
|
72 |
$suggestion->STATUS('REJECTED')->store; |
| 72 |
$suggestion->STATUS('ASKED')->store; |
73 |
$suggestion->STATUS('ASKED')->store; |
| 73 |
my $last_message = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->single; |
74 |
my $messages_sent = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } ); |
| 74 |
if ( !defined $last_message ) { |
|
|
| 75 |
$last_message = "No message was sent"; |
| 76 |
} |
| 77 |
is( |
75 |
is( |
| 78 |
$last_message, 'No message was sent', |
76 |
$messages_sent->count, 1, |
| 79 |
'If EmailPurchaseSuggestions is not enabled, a message should not be sent' |
77 |
'If EmailPurchaseSuggestions is not enabled, a message should not be sent' |
| 80 |
); |
78 |
); |
| 81 |
|
79 |
|
| 82 |
t::lib::Mocks::mock_preference( 'EmailPurchaseSuggestions', 'EmailAddressForSuggestions' ); |
80 |
t::lib::Mocks::mock_preference( 'EmailPurchaseSuggestions', 'EmailAddressForSuggestions' ); |
| 83 |
Koha::Notice::Messages->search->delete; |
81 |
Koha::Notice::Messages->search->delete; |
|
|
82 |
$suggestion->STATUS('REJECTED')->store; |
| 84 |
$suggestion->STATUS('ASKED')->store; |
83 |
$suggestion->STATUS('ASKED')->store; |
| 85 |
$last_message = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->single; |
84 |
$messages_sent = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } ); |
| 86 |
if ( !defined $last_message ) { |
85 |
is( $messages_sent->count, 1, 'If EmailPurchaseSuggestions is enabled and the status of suggestion is set to ASKED, a message should be sent' ); |
| 87 |
fail('No message was sent'); |
86 |
is( |
| 88 |
} else { |
87 |
$messages_sent->next->letter_code, 'NEW_SUGGESTION', |
| 89 |
is( |
88 |
'If EmailPurchaseSuggestions is enabled and the status of suggestion is set to ASKED, a message should be sent' |
| 90 |
$last_message->letter_code, 'NEW_SUGGESTION', |
89 |
); |
| 91 |
'If EmailPurchaseSuggestions is enabled and the status of suggestion is set to ASKED, a message should be sent' |
90 |
|
| 92 |
); |
91 |
Koha::Notice::Messages->search->delete; |
| 93 |
} |
92 |
$suggestion->set( { note => 'a note' } )->store; |
|
|
93 |
$messages_sent = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } ); |
| 94 |
is( $messages_sent->count, 1, 'NEW_SUGGESTION should not be sent again if status has not changed' ); |
| 94 |
|
95 |
|
| 95 |
Koha::Notice::Messages->search->delete; |
96 |
Koha::Notice::Messages->search->delete; |
| 96 |
$suggestion->STATUS('ACCEPTED')->store; |
97 |
$suggestion->STATUS('ACCEPTED')->store; |
| 97 |
$last_message = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->single; |
98 |
$messages_sent = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } ); |
| 98 |
if ( !defined $last_message ) { |
|
|
| 99 |
$last_message = "No message was sent"; |
| 100 |
} |
| 101 |
is( |
99 |
is( |
| 102 |
$last_message, 'No message was sent', |
100 |
$messages_sent->count, 0, |
| 103 |
'If the status of suggestion is not set to ASKED, a message should not be sent' |
101 |
'If the status of suggestion is not set to ASKED, a message should not be sent' |
| 104 |
); |
102 |
); |
| 105 |
|
103 |
|
| 106 |
- |
|
|