mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 19:44:09 +00:00
Add validation and flash message for invalid date range in Reports
Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com>
This commit is contained in:
@@ -92,6 +92,24 @@ class ReportsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :ok # Should not crash, uses defaults
|
||||
end
|
||||
|
||||
test "index swaps dates when end_date is before start_date" do
|
||||
start_date = Date.current
|
||||
end_date = 1.month.ago.to_date
|
||||
|
||||
get reports_path(
|
||||
period_type: :custom,
|
||||
start_date: start_date.to_s,
|
||||
end_date: end_date.to_s
|
||||
)
|
||||
|
||||
assert_response :ok
|
||||
# Should show flash message about invalid date range
|
||||
assert flash[:alert].present?, "Flash alert should be present"
|
||||
assert_match /End date cannot be before start date/, flash[:alert]
|
||||
# Should display the swapped date range
|
||||
assert_select ".text-sm.text-secondary", text: /Showing data from #{Regexp.escape(end_date.strftime("%b %-d, %Y"))} to #{Regexp.escape(start_date.strftime("%b %-d, %Y"))}/
|
||||
end
|
||||
|
||||
test "spending patterns returns data when expense transactions exist" do
|
||||
# Create expense category
|
||||
expense_category = @family.categories.create!(
|
||||
@@ -185,4 +203,21 @@ class ReportsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :ok, "Export should work with session auth. Response: #{@response.body}"
|
||||
assert_equal "text/csv", @response.media_type
|
||||
end
|
||||
|
||||
test "export transactions swaps dates when end_date is before start_date" do
|
||||
start_date = Date.current
|
||||
end_date = 1.month.ago.to_date
|
||||
|
||||
get export_transactions_reports_path(
|
||||
format: :csv,
|
||||
period_type: :custom,
|
||||
start_date: start_date.to_s,
|
||||
end_date: end_date.to_s
|
||||
)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal "text/csv", @response.media_type
|
||||
# Verify the CSV content is generated (should not crash)
|
||||
assert_not_nil @response.body
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user