Commit 69628f02 authored by David Lucadou's avatar David Lucadou

Added more tests

parent 69186b8d
Pipeline #60929037 passed with stage
in 9 minutes and 35 seconds
......@@ -29,21 +29,27 @@ RSpec.describe "AdminReportsSearch", type: :request do
(120..124).each do |n|
create_report_with(msg_id: n, reason: "/reAsOn #{n}")
end
(124..126).each do |n|
[124, 126].each do |n|
create_report_with(msg_id: n, reason: "/rEason #{n}/")
end
(126..130).each do |n|
create_report_with(msg_id: n, reason: "reasOn #{n}/")
end
switch_to_user(email_1, password_1)
(125..130).each do |n|
(126..130).each do |n|
create_report_with(msg_id: n, reason: "rEasOn #{n}")
end
name_3 = 'Test User 3'
email_3 = 'testuser3@domain.test'
password_3 = 'CorrectHorseBatteryStaple3'
sign_out_with()
sign_up_with(name_3, email_3, password_3, password_3)
admin_email = 'admin@domain.example'
admin_password = 'passwordpassword1'
switch_to_user(admin_email, admin_password)
sign_in_with(admin_email, admin_password)
@basic_user_1 = {username: email_1, password: password_1}
@basic_user_2 = {username: email_2, password: password_2}
@basic_user_3 = {username: email_3, password: password_3}
@admin_user = {username: admin_email, password: admin_password}
visit admin_reports_path
end
......@@ -54,7 +60,8 @@ RSpec.describe "AdminReportsSearch", type: :request do
# See reports from Test User 1
expect(page).to have_content("rEasOn 130")
expect(page).to have_content("rEasOn 128")
expect(page).to have_content("rEasOn 125")
expect(page).to have_content("rEasOn 126")
# See reports from Test User 2
expect(page).to have_content("reasOn 130/")
expect(page).to have_content("reasOn 128/")
......@@ -66,18 +73,128 @@ RSpec.describe "AdminReportsSearch", type: :request do
search_admin_reports_with()
expect(page).to have_content("rEasOn 130")
expect(page).to have_content("rEasOn 128")
expect(page).to have_content("rEasOn 125")
expect(page).to have_content("rEasOn 126")
expect(page).to have_content("reasOn 130/")
expect(page).to have_content("reasOn 128/")
expect(page).to have_content("reasOn 127/")
expect(page).to have_link("Next ›", href: "/admin/reports?advanced_query=&channel=&end_time=&page=2&per_page=&reason=&resolved=all&resolver_id=&sender=&start_time=&user_id=")
expect(page).to have_link("Last »", href: "/admin/reports?advanced_query=&channel=&end_time=&page=10&per_page=&reason=&resolved=all&resolver_id=&sender=&start_time=&user_id=")
end
it "search all reports with a report status"
it "search all reports with a reporting user ID"
# email and ID
it "search all reports with a message channel"
it "search all reports with a message sender"
it "search all reports with a report status" do
# Resolve some reports
last_report = Report.last.id
(last_report - 15..last_report).step(3) do |n|
resolve_report(n, resolving_action: "Resolved #{n}", switch_to_user: nil, switch_back_user: nil)
end
# Resolved reports
search_admin_reports_with(report_status: 'Resolved')
(last_report - 15..last_report).step(3) do |n|
expect(page).to have_content("Resolved #{n}")
expect(page).to have_link("Show", href: report_path(n))
expect(page).not_to have_link("Show", href: report_path(n - 1))
expect(page).not_to have_link("Show", href: report_path(n - 2))
end
# Unresolved reports
search_admin_reports_with(report_status: 'Unresolved')
(last_report - 15..last_report).step(3) do |n|
expect(page).not_to have_content("Resolved #{n}")
expect(page).not_to have_link("Show", href: report_path(n))
end
(last_report - 12..last_report).step(3) do |n|
# I have to have separate loops because the 17th and 16th reports will
# not show up - that would be 12 reports when it's 10 per page.
expect(page).to have_link("Show", href: report_path(n - 1))
expect(page).to have_link("Show", href: report_path(n - 2))
end
end
it "search all reports with a reporting user ID" do
# Search for valid user ID
user_1 = User.where(email: @basic_user_1[:username]).first
search_admin_reports_with(report_user_id: user_1.id)
(126..130).each do |n|
expect(page).to have_content("rEasOn #{n}")
end
(17..20).each do |n|
expect(page).to have_content("Reason #{n}")
end
expect(page).to have_link("Next ›", href: "/admin/reports?advanced_query=&channel=&end_time=&page=2&per_page=&reason=&resolved=all&resolver_id=&sender=&start_time=&user_id=#{user_1.id}")
expect(page).to have_link("Last »", href: "/admin/reports?advanced_query=&channel=&end_time=&page=3&per_page=&reason=&resolved=all&resolver_id=&sender=&start_time=&user_id=#{user_1.id}")
# Searh for valid user email
user_2 = User.where(email: @basic_user_2[:username]).first
search_admin_reports_with(report_user_id: user_2.email)
(126..130).each do |n|
expect(page).to have_content("reasOn #{n}/")
end
[124, 126].each do |n|
expect(page).to have_content("/rEason #{n}/")
end
(123..124).each do |n|
expect(page).to have_content("/reAsOn #{n}")
end
expect(page).to have_link("Next ›", href: "/admin/reports?advanced_query=&channel=&end_time=&page=2&per_page=&reason=&resolved=all&resolver_id=&sender=&start_time=&user_id=#{ERB::Util.url_encode(user_2.email)}")
expect(page).to have_link("Last »", href: "/admin/reports?advanced_query=&channel=&end_time=&page=4&per_page=&reason=&resolved=all&resolver_id=&sender=&start_time=&user_id=#{ERB::Util.url_encode(user_2.email)}")
# Search for user who has not reported anything
user_3 = User.where(email: @basic_user_3[:username]).first
search_admin_reports_with(report_user_id: user_3.id)
expect(page).to have_content("No reports")
expect(page).not_to have_content("Next ›")
end
it "search all reports with a message channel that exists" do
# Channel with reported messages
search_admin_reports_with(msg_channel: '#channel12345678901234567_')
expect(page).not_to have_content("#luna_moona")
expect(page).not_to have_content("#tla")
expect(page).to have_content("rEasOn 126")
expect(page).to have_content("reasOn 126/")
expect(page).to have_content("/rEason 126/")
# Channel with no reported messages
search_admin_reports_with(msg_channel: '#tla')
puts page.html
expect(page).to have_content("No reports")
expect(page).not_to have_content("Next ›")
end
it "search all reports with a message channel that does not exist" do
# Channel is a partial match of one that exists and has reported messages
search_admin_reports_with(msg_channel: '#channel1234567890')
expect(page).to have_content("No reports")
expect(page).not_to have_content("Next ›")
# Channel is not a partial match and has no messages
search_admin_reports_with(msg_channel: '#nonexistentchannel')
expect(page).to have_content("No reports")
expect(page).not_to have_content("Next ›")
end
it "search all reports with a message sender that exists" do
# Message sender has reported messages
search_admin_reports_with(msg_sender: 'oldmario')
[13, 15, 18, 24, 28].each do |n|
# These are some message IDs I selected, it's not wholly inclusive
expect(page).to have_content("ReaSoN #{n}")
end
expect(page).to have_link("Next ›", href: "/admin/reports?advanced_query=&channel=&end_time=&page=2&per_page=&reason=&resolved=all&resolver_id=&sender=oldmario&start_time=&user_id=")
expect(page).to have_link("Last »", href: "/admin/reports?advanced_query=&channel=&end_time=&page=3&per_page=&reason=&resolved=all&resolver_id=&sender=oldmario&start_time=&user_id=")
# Message sender has no reported messages
search_admin_reports_with(msg_sender: 'rickeon')
expect(page).to have_content("No reports")
expect(page).not_to have_content("Next ›")
end
it "search all reports with a message sender that does not exist" do
# Sender is a partial match of one that exists and has reported messages
search_admin_reports_with(msg_sender: 'oldmar')
expect(page).to have_content("No reports")
expect(page).not_to have_content("Next ›")
# Sender is not a partial match and has no messages
search_admin_reports_with(msg_sender: 'notarealuser')
expect(page).to have_content("No reports")
expect(page).not_to have_content("Next ›")
end
it "search all reports with a case insensitive report reason without regex"
it "search all reports with a case sensitive report reason with regex"
it "search all reports with a case insensitive report reason with escaped regex"
......
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