Skip to content

Commit

Permalink
add system tests for moderation (#7268)
Browse files Browse the repository at this point in the history
* add system tests for moderation

* consistency

* remove unfinished test
  • Loading branch information
Uzay-G authored and jywarren committed Jan 17, 2020
1 parent 474ac7b commit d97bac2
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions test/system/moderation_tests.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d97bac2

Please sign in to comment.