Commit 2ae91d02 authored by David Lucadou's avatar David Lucadou

Filled out more tests

parent a74777e5
Pipeline #60241516 passed with stage
in 8 minutes and 17 seconds
......@@ -277,6 +277,10 @@ RSpec.describe "UserReportsSearch", type: :request do
# Will not return all reports
first_report = Report.find(Report.last.id - 4)
first_report.created_at = Time.now.utc - 5.minutes
# Because all these reports are created one after the other (and will
# occur in less than a minute, smaller than the 1 minute increments
# allowed on the date reported field), I have to adjust the created_at
# attribute on 1 of them to have anything to look for.
first_report.save!
search_user_reports_with(start_time: (Time.now.utc - 3.minutes).strftime('%Y-%m-%d %H:%M'), expecting_before: ['Report 1', 'RePoRt 1', '/rEpOrT 2/', '/report 3', '(REPORT 4)'], expecting_after: ['RePoRt 1', '/rEpOrT 2/', '/report 3', '(REPORT 4)'])
expect(page).not_to have_content("Failed to execute search, see errors below")
......@@ -307,9 +311,198 @@ RSpec.describe "UserReportsSearch", type: :request do
expect(page).not_to have_content("/report 3")
expect(page).not_to have_content("(REPORT 4)")
end
it "search their reports with a starting and ending reported time before the current system time"
it "search their reports with a custom results per page"
it "search their reports with multiple fields filled in"
it "search their reports with a starting and ending reported time before the current system time" do
# Will return some reports
# Modify creation dates for multiple reports
report = Report.find(Report.last.id - 4) # 'Report 1'
report.created_at = Time.now.utc - 5.minutes
report.save!
report = Report.find(Report.last.id - 3) # 'RePoRt 1'
report.created_at = Time.now.utc - 4.minutes
report.save!
report = Report.find(Report.last.id - 2) # '/rEpOrT 2/'
report.created_at = Time.now.utc - 3.minutes
report.save!
report = Report.find(Report.last.id - 1) # '/report 3'
report.created_at = Time.now.utc - 2.minutes
report.save!
report = Report.find(Report.last.id) # '(REPORT 4)'
report.created_at = Time.now.utc - 1.minutes
report.save!
search_user_reports_with(start_time: (Time.now.utc - 4.minutes).strftime('%Y-%m-%d %H:%M'), end_time: (Time.now.utc - 2.minutes).strftime('%Y-%m-%d %H:%M'), expecting_before: ['Report 1', 'RePoRt 1', '/rEpOrT 2/', '/report 3', '(REPORT 4)'], expecting_after: ['RePoRt 1', '/rEpOrT 2/'])
expect(page).not_to have_content("Failed to execute search, see errors below")
expect(page).not_to have_content("Report 1")
expect(page).not_to have_content("/report 3")
expect(page).not_to have_content("(REPORT 4)")
# Will return all reports
search_user_reports_with(start_time: (Time.now.utc - 6.minutes).strftime('%Y-%m-%d %H:%M'), end_time: (Time.now.utc).strftime('%Y-%m-%d %H:%M'), expecting_before: ['Report 1', 'RePoRt 1', '/rEpOrT 2/', '/report 3', '(REPORT 4)'], expecting_after: ['Report 1', 'RePoRt 1', '/rEpOrT 2/', '/report 3', '(REPORT 4)'])
expect(page).not_to have_content("Failed to execute search, see errors below")
end
it "search their reports with a custom results per page" do
# Generate lots more reports
report = 5
(110...130).each do |n|
create_report_with(msg_id: n, reason: "Report #{report}", expecting_before: [ChatLog.find(n).channel, ChatLog.find(n).message])
report += 1
end
# Make sure these reports are visible - 11 per page
search_user_reports_with(per_page: 11)
expect(page).to have_content("Report 24")
expect(page).to have_content("Report 20")
expect(page).to have_content("Report 17")
expect(page).to have_link("Next ›", href: "/account/reports?advanced_query=&channel=&end_time=&msg_id=&page=2&per_page=11&reason=&resolved=all&sender=&start_time=")
expect(page).to have_link("Last »", href: "/account/reports?advanced_query=&channel=&end_time=&msg_id=&page=3&per_page=11&reason=&resolved=all&sender=&start_time=")
click_on "Next ›"
expect(page).to have_content("Report 13")
expect(page).to have_content("Report 10")
expect(page).to have_content("Report 6")
click_on "Next ›"
expect(page).to have_content("/rEpOrT 2/")
expect(page).to have_content("RePoRt 1")
expect(page).to have_content("Report 1")
expect(page).to have_link("« First", href: "/account/reports?advanced_query=&channel=&end_time=&msg_id=&per_page=11&reason=&resolved=all&sender=&start_time=")
expect(page).to have_link("‹ Prev", href: "/account/reports?advanced_query=&channel=&end_time=&msg_id=&page=2&per_page=11&reason=&resolved=all&sender=&start_time=")
# 15 per page
search_user_reports_with(per_page: 15)
expect(page).to have_content("Report 24")
expect(page).to have_content("Report 20")
expect(page).to have_content("Report 17")
expect(page).to have_content("Report 13")
expect(page).to have_content("Report 10")
expect(page).to have_link("Next ›", href: "/account/reports?advanced_query=&channel=&end_time=&msg_id=&page=2&per_page=15&reason=&resolved=all&sender=&start_time=")
expect(page).to have_link("Last »", href: "/account/reports?advanced_query=&channel=&end_time=&msg_id=&page=2&per_page=15&reason=&resolved=all&sender=&start_time=")
click_on "Next ›"
expect(page).to have_content("Report 6")
expect(page).to have_content("/rEpOrT 2/")
expect(page).to have_content("RePoRt 1")
expect(page).to have_content("Report 1")
expect(page).to have_link("« First", href: "/account/reports?advanced_query=&channel=&end_time=&msg_id=&per_page=15&reason=&resolved=all&sender=&start_time=")
expect(page).to have_link("‹ Prev", href: "/account/reports?advanced_query=&channel=&end_time=&msg_id=&per_page=15&reason=&resolved=all&sender=&start_time=")
# 30 per page
search_user_reports_with(per_page: 30)
expect(page).to have_content("Report 24")
expect(page).to have_content("Report 20")
expect(page).to have_content("Report 17")
expect(page).to have_content("Report 13")
expect(page).to have_content("Report 10")
expect(page).to have_content("Report 6")
expect(page).to have_content("/rEpOrT 2/")
expect(page).to have_content("RePoRt 1")
expect(page).to have_content("Report 1")
expect(page).not_to have_content("Next ›")
expect(page).not_to have_content("Last »")
end
it "search their reports with multiple fields filled in" do
# Resolve a few
last_report = Report.last.id
resolve_report(last_report, resolving_action: 'Cats make about 100 different sounds, while dogs make only about 10') # '(REPORT 4)'
resolve_report(last_report - 4, resolving_action: 'A cat usually has about 12 whiskers on each side of its face') # 'Report 1'
# Status, reason (no regex)
search_user_reports_with(report_status: 'Unresolved', report_reason: 'report', expecting_before: ['Report 1', 'RePoRt 1', '/rEpOrT 2/', '/report 3', '(REPORT 4)'], expecting_after: ['RePoRt 1', '/rEpOrT 2/', '/report 3'])
expect(page).not_to have_content("Failed to execute search, see errors below")
# Status, reason (regex)
search_user_reports_with(report_status: 'Unresolved', report_reason: '/(Re|rE)/', expecting_before: ['Report 1', 'RePoRt 1', '/rEpOrT 2/', '/report 3', '(REPORT 4)'], expecting_after: ['RePoRt 1', '/rEpOrT 2/'])
expect(page).not_to have_content("Failed to execute search, see errors below")
expect(page).not_to have_content("Report 1")
expect(page).not_to have_content("/report 3")
expect(page).not_to have_content("(REPORT 4)")
# Create another report
create_report_with(msg_id: 39, reason: 'report 5', expecting_before: ['#stereotonetim', 'timOh'])
# Status, message text (regex)
search_user_reports_with(msg_text: '/tim(Plus|Minus|oh)/', expecting_before: ['Report 1', 'RePoRt 1', '/rEpOrT 2/', '/report 3', '(REPORT 4)', 'report 5'], expecting_after: ['/report 3', 'timPlus', '(REPORT 4)', 'I can\'t believe I missed it! timMinus'])
expect(page).not_to have_content("Failed to execute search, see errors below")
expect(page).not_to have_content("Report 1")
expect(page).not_to have_content("RePoRt 1")
expect(page).not_to have_content("25 letter channel name for testing")
expect(page).not_to have_content("/rEpOrT 2/")
expect(page).not_to have_content("\"big pink balloon rabbit destroys wildlife\"")
expect(page).not_to have_content("report 5")
expect(page).not_to have_content("timOh")
# Create more reports for the next test
(6..15).each do |n|
create_report_with(msg_id: 126, reason: "report #{n}", expecting_before: ['#channel12345678901234567_', '25 letter channel name for testing'])
end
# Message ID
search_user_reports_with(msg_id: 126)
expect(page).not_to have_content("Failed to execute search, see errors below")
expect(page).to have_content("report 15")
expect(page).to have_content("report 12")
expect(page).to have_content("report 9")
expect(page).to have_content("report 6")
expect(page).to have_link("Next ›", href: "/account/reports?advanced_query=&channel=&end_time=&msg_id=126&page=2&per_page=&reason=&resolved=all&sender=&start_time=")
expect(page).to have_link("Last »", href: "/account/reports?advanced_query=&channel=&end_time=&msg_id=126&page=2&per_page=&reason=&resolved=all&sender=&start_time=")
# Generate a bunch more reports
(16..30).each do |n|
create_report_with(msg_id: 126, reason: "Report #{n}", expecting_before: ['#channel12345678901234567_', '25 letter channel name for testing'])
end
# Modify all the creation dates so the oldest will be created 35 minutes
# ago and increments by 1 minute intervals
offset = 35
# Why did I choose 35? Because I currently have 30 reports created,
# so it gives me a little bit of leeway before I would end up with
# reports being created in the future, which might break the tests.
# Initially I was using the ID of the reports, but as you test over
# and over, the IDs start getting into the thousands and mess
# everything up. Kinda brittle, but not too difficult to adjust.
User.where(email: 'testuser@domain.test').first.reports.each do |report|
# I can't use current_user.reports or Current.user.reports in this
# context.
report.created_at = Time.now.utc - offset.minutes
report.save!
offset -= 1
# I initially used reports.reverse_order.each, but modifying creation
# date can end up reordering things so I ended up with some reports
# not being touched and others being modified multiple times.
# That is why I have to decrement offset each time.
end
# Status, date reported end, per page
search_user_reports_with(report_status: 'Unresolved', end_time: (Time.now.utc - 10.minutes).strftime('%Y-%m-%d %H:%M'), expecting_before: ['Report 30', 'Report 25', 'Report 21'], expecting_after: ['Report 23', 'Report 19', 'report 15'])
expect(page).not_to have_content("Failed to execute search, see errors below")
expect(page).not_to have_content("Report 30")
expect(page).not_to have_content("Report 25")
# Message channel, per page
search_user_reports_with(msg_channel: '#channel12345678901234567_', per_page: 15, expecting_before: ['Report 30', 'Report 25', 'Report 21'], expecting_after: ['Report 30', 'Report 25', 'Report 21', 'Report 16'])
expect(page).not_to have_content("Failed to execute search, see errors below")
expect(page).to have_link("Next ›", href: "/account/reports?advanced_query=&channel=%23channel12345678901234567_&end_time=&msg_id=&page=2&per_page=15&reason=&resolved=all&sender=&start_time=")
expect(page).to have_link("Last »", href: "/account/reports?advanced_query=&channel=%23channel12345678901234567_&end_time=&msg_id=&page=2&per_page=15&reason=&resolved=all&sender=&start_time=")
# Resolve some reports
last_report = Report.last.id
resolve_report(last_report - 1) # 'Report 29'
resolve_report(last_report - 3) # 'Report 27'
resolve_report(last_report - 15) # 'Report 15'
# Status, message sender
search_user_reports_with(report_status: 'Resolved', msg_sender: 'luna_moona', expecting_before: ['Report 30', 'Report 25', 'Report 21'], expecting_after: ['Report 29', 'Report 27', 'report 15', 'Report 1'])
expect(page).not_to have_content("Failed to execute search, see errors below")
expect(page).not_to have_content("Report 30")
expect(page).not_to have_content("Report 25")
expect(page).not_to have_content("Report 21")
expect(page).not_to have_content("Next ›")
# Date reported start, message text (regex)
start_time = User.where(email: 'testuser@domain.test').first.reports.where(msg_text: 'timOh').first.created_at
search_user_reports_with(msg_text: '/tim(Plus|Minus|Oh)/', start_time: start_time, expecting_before: ['Report 30', 'Report 25', 'Report 21'], expecting_after: ['report 5', 'timOh'])
expect(page).not_to have_content("Failed to execute search, see errors below")
expect(page).not_to have_content("/report 3")
expect(page).not_to have_content("timPlus")
expect(page).not_to have_content("(REPORT 4)")
expect(page).not_to have_content("I can't believe I missed it! timMinus")
end
end
describe "User cannot" do
......
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