+# Test budgetid fk
+$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB
+my $my_suggestionid_test_budgetid = NewSuggestion($my_suggestion);
+$suggestion = GetSuggestion($my_suggestionid_test_budgetid);
+is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' );
+
+$my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB
+ModSuggestion( $my_suggestion );
+$suggestion = GetSuggestion($my_suggestionid_test_budgetid);
+is( $suggestion->{budgetid}, undef, 'NewSuggestion Should set budgetid to NULL if equals an empty string' );
+
+subtest 'GetUnprocessedSuggestions' => sub {
+ plan tests => 11;
+ $dbh->do(q|DELETE FROM suggestions|);
+ my $my_suggestionid = NewSuggestion($my_suggestion);
+ my $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
+ is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund' );
+ my $status = ModSuggestion($mod_suggestion1);
+ my $suggestion = GetSuggestion($my_suggestionid);
+ is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' );
+ ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } );
+ $suggestion = GetSuggestion($my_suggestionid);
+ is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' );
+
+ $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
+ is( scalar(@$unprocessed_suggestions), 1, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' );
+
+ warning_is { ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'REJECTED' } ) }
+ 'No suggestions REJECTED letter transported by email',
+ 'Warning raised if no REJECTED letter by email';
+ $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
+ is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should return the suggestion if the suggestion is linked to a fund and has not been processed yet' );
+
+ warning_is { ModSuggestion( { suggestionid => $my_suggestionid, STATUS => 'ASKED', suggesteddate => dt_from_string->add_duration( DateTime::Duration->new( days => -4 ) ) } ); }
+ 'No suggestions ASKED letter transported by email',
+ 'Warning raised if no ASKED letter by email';
+ $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
+ is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should use 0 as default value for days' );
+ $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(4);
+ is( scalar(@$unprocessed_suggestions), 1, 'GetUnprocessedSuggestions should return the suggestion suggested 4 days ago' );
+ $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(3);
+ is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 3 days ago' );
+ $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions(5);
+ is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' );
+};