From d97bac26b93fe560841f195aec2bbe0acd0b2838 Mon Sep 17 00:00:00 2001 From: Uzay-G <52892257+Uzay-G@users.noreply.github.com> Date: Fri, 17 Jan 2020 01:19:16 +0100 Subject: [PATCH] add system tests for moderation (#7268) * add system tests for moderation * consistency * remove unfinished test --- test/system/moderation_tests.rb | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/system/moderation_tests.rb diff --git a/test/system/moderation_tests.rb b/test/system/moderation_tests.rb new file mode 100644 index 0000000000..7aaa2c8500 --- /dev/null +++ b/test/system/moderation_tests.rb @@ -0,0 +1,66 @@ +require "application_system_test_case" + +class ModerationTest < ApplicationSystemTestCase + + def setup + visit "/" + click_on "Login" + fill_in 'user_session[username]', with: 'palpatine' + fill_in 'user_session[password]', with: 'secretive' + click_on "Log in" + end + + test "banning and unbanning a user" do + visit "/profile/#{users(:bob).username}" + + find("a#info-ellipsis").click + accept_confirm "Are you sure? The user will no longer be able to log in or publish, and their content will be hidden." do + find("a[href='/ban/#{users(:bob).id}'").click() + end + assert find("div.alert", text: "That user has been banned.") + + find("a#info-ellipsis").click + find("a[href='/unban/#{users(:bob).id}'").click() + assert find("div.alert", text: "The user has been unbanned.") + end + + test "moderating and unmoderating a user" do + visit "/profile/#{users(:bob).username}" + + find("a#info-ellipsis").click() + accept_confirm "Are you sure? The user will no longer be able to log in or publish." do + find("a[href='/admin/moderate/#{users(:bob).id}'").click() + end + assert find("div.alert", text: "That user has been placed in moderation.") + + find("a#info-ellipsis").click() + find("a[href='/admin/unmoderate/#{users(:bob).id}'").click() + assert find("div.alert", text: "The user has been unmoderated.") + end + + test "batch-spamming users" do + banned_page = nodes(:spam_targeted_page) + banned_page2 = nodes(:wiki_page) + visit "/spam/batch/#{banned_page.id},#{banned_page2.id}" + page.assert_selector "div.alert-success" + + # verify pages are spammed + visit banned_page.path + assert find("div.alert", text: "That page has been moderated as spam. Please contact web@publiclab.org if you believe there is a problem.") + + visit banned_page2.path + assert find("div.alert", text: "That page has been moderated as spam. Please contact web@publiclab.org if you believe there is a problem.") + + # verify note authors are banned + visit "/" + visit "/profile/#{banned_page.author.username}" + assert find("div.alert", text: "That user has been banned.") + find("a#info-ellipsis").click() + page.assert_selector "a[href='/unban/#{banned_page.author.id}'" + + visit "/profile/#{banned_page2.author.username}" + assert find("div.alert", text: "That user has been banned.") + find("a#info-ellipsis").click() + page.assert_selector "a[href='/unban/#{banned_page2.author.id}'" + end +end