Commit a59f2a5c authored by David Lucadou's avatar David Lucadou

Changed error message wording and added more tests

parent 6f3184c4
Pipeline #60406897 passed with stage
in 9 minutes and 13 seconds
......@@ -46,7 +46,7 @@ class ReportsController < ApplicationController
# Validate report_type
if report_type && report_statuses.key(report_type).nil?
@SearchErrors << "Invalid search type, please select an option from the dropdown menu"
@SearchErrors << "Invalid report status, please select an option from the dropdown menu"
elsif report_type
if report_type == 'all'
report_status = nil
......
......@@ -702,10 +702,64 @@ RSpec.describe "UserReportsSearch", type: :request do
expect(page).to have_content("Invalid reported message ID, must be a positive integer")
expect(page).to have_content("A blank search has been executed")
end
it "search their reports with an invalid message text regex"
it "search their reports with an invalid report status"
# easiest way is probably going to be going to the path "/account/reports?utf8=✓&resolved=an_invalid_value"
it "search their reports with an invalid report reason regex"
it "search their reports with an invalid message text regex" do
search_user_reports_with(msg_text: '/\(closed parenthesis for regex testing)/')
expect(page).to have_content("Failed to execute search, see errors below")
expect(page).to have_content("1 error prohibited your search from being executed")
expect(page).to have_content("Invalid regex in message text, please double check your query. Error details: unmatched close parenthesis")
search_user_reports_with(msg_text: '/(closed parenthesis for regex testing\)/')
expect(page).to have_content("Failed to execute search, see errors below")
expect(page).to have_content("1 error prohibited your search from being executed")
expect(page).to have_content("Invalid regex in message text, please double check your query. Error details: end pattern with unmatched parenthesis")
search_user_reports_with(msg_text: '/[closed parenthesis for regex testing\)/')
expect(page).to have_content("Failed to execute search, see errors below")
expect(page).to have_content("1 error prohibited your search from being executed")
expect(page).to have_content("Invalid regex in message text, please double check your query. Error details: premature end of char-class")
end
it "search their reports with an invalid report status" do
# There is no good way to force a new value into the dropdown menu
# without using JS to modify the page, but since this is a simple GET,
# I can just set a custom report status in the URL
visit "/account/reports?utf8=#{URI.encode('✓')}&resolved=aaaAAAAAAaaaaaaaa"
expect(page).to have_content("Failed to execute search, see errors below")
expect(page).to have_content("1 error prohibited your search from being executed")
expect(page).to have_content("Invalid report status, please select an option from the dropdown menu")
# Check to make sure changing capitalization of valid statuses results
# in an error
visit "/account/reports?utf8=#{URI.encode('✓')}&resolved=Resolved"
# Without the URI.encode, I get a URI::InvalidURIError due to having
# non-ASCII characters. This ocurs even if I do "utf8=\u2713", so
# there is no way around using URI.encode.
# https://stackoverflow.com/a/50158549
expect(page).to have_content("Failed to execute search, see errors below")
expect(page).to have_content("1 error prohibited your search from being executed")
expect(page).to have_content("Invalid report status, please select an option from the dropdown menu")
# Check to make sure an absurdly long status displays an error message
visit "/account/reports?utf8=#{URI.encode('✓')}&resolved=#{'e' * 256}"
expect(page).to have_content("Failed to execute search, see errors below")
expect(page).to have_content("1 error prohibited your search from being executed")
expect(page).to have_content("Invalid report status, please select an option from the dropdown menu")
end
it "search their reports with an invalid report reason regex" do
search_user_reports_with(report_reason: '/\(closed parenthesis for regex testing)/')
expect(page).to have_content("Failed to execute search, see errors below")
expect(page).to have_content("1 error prohibited your search from being executed")
expect(page).to have_content("Invalid regex in reporting reason, please double check your query. Error details: unmatched close parenthesis")
search_user_reports_with(report_reason: '/(closed parenthesis for regex testing\)/')
expect(page).to have_content("Failed to execute search, see errors below")
expect(page).to have_content("1 error prohibited your search from being executed")
expect(page).to have_content("Invalid regex in reporting reason, please double check your query. Error details: end pattern with unmatched parenthesis")
search_user_reports_with(report_reason: '/[closed parenthesis for regex testing\)/')
expect(page).to have_content("Failed to execute search, see errors below")
expect(page).to have_content("1 error prohibited your search from being executed")
expect(page).to have_content("Invalid regex in reporting reason, please double check your query. Error details: premature end of char-class")
end
it "search their reports with a starting reported time after the current system time" do
year = Time.now.year + 5
search_user_reports_with(start_time: "#{year}-01-01 09:00", expecting_before: ['Report 1', 'RePoRt 1', '/rEpOrT 2/', '/report 3', '(REPORT 4)'], expecting_after: ['Failed to execute search, see errors below', 'Starting time cannot be greater than the current system time', 'A blank search has been executed', 'Report 1', 'RePoRt 1', '/rEpOrT 2/', '/report 3', '(REPORT 4)'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment