2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-08-19 07:14:26 -04:00
|
|
|
require_dependency 'flag_query'
|
|
|
|
|
|
|
|
describe FlagQuery do
|
|
|
|
|
|
|
|
let(:codinghorror) { Fabricate(:coding_horror) }
|
|
|
|
|
|
|
|
describe "flagged_posts_report" do
|
2017-05-08 13:13:35 -04:00
|
|
|
it "does not return flags on system posts" do
|
|
|
|
admin = Fabricate(:admin)
|
|
|
|
post = create_post(user: Discourse.system_user)
|
|
|
|
PostAction.act(codinghorror, post, PostActionType.types[:spam])
|
|
|
|
posts, topics, users = FlagQuery.flagged_posts_report(admin, "")
|
|
|
|
|
|
|
|
expect(posts).to be_blank
|
|
|
|
expect(topics).to be_blank
|
|
|
|
expect(users).to be_blank
|
|
|
|
end
|
|
|
|
|
2013-08-19 07:14:26 -04:00
|
|
|
it "operates correctly" do
|
2014-02-06 22:11:52 -05:00
|
|
|
admin = Fabricate(:admin)
|
|
|
|
moderator = Fabricate(:moderator)
|
|
|
|
|
2013-08-19 07:14:26 -04:00
|
|
|
post = create_post
|
|
|
|
post2 = create_post
|
|
|
|
|
|
|
|
user2 = Fabricate(:user)
|
|
|
|
user3 = Fabricate(:user)
|
|
|
|
|
|
|
|
PostAction.act(codinghorror, post, PostActionType.types[:spam])
|
|
|
|
PostAction.act(user2, post, PostActionType.types[:spam])
|
2017-08-14 09:16:47 -04:00
|
|
|
mod_message = PostAction.act(user3, post, PostActionType.types[:notify_moderators], message: "this is a :one::zero:")
|
2013-08-19 07:14:26 -04:00
|
|
|
|
|
|
|
PostAction.act(codinghorror, post2, PostActionType.types[:spam])
|
|
|
|
PostAction.act(user2, post2, PostActionType.types[:spam])
|
|
|
|
|
2014-07-28 13:17:37 -04:00
|
|
|
posts, topics, users = FlagQuery.flagged_posts_report(admin, "")
|
2017-08-14 09:16:47 -04:00
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(posts.count).to eq(2)
|
2013-08-19 07:14:26 -04:00
|
|
|
first = posts.first
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(users.count).to eq(5)
|
|
|
|
expect(first[:post_actions].count).to eq(2)
|
2013-08-19 07:14:26 -04:00
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(topics.count).to eq(2)
|
2014-07-28 13:17:37 -04:00
|
|
|
|
2013-08-19 07:14:26 -04:00
|
|
|
second = posts[1]
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(second[:post_actions].count).to eq(3)
|
|
|
|
expect(second[:post_actions].first[:permalink]).to eq(mod_message.related_post.topic.relative_url)
|
2017-08-14 09:16:47 -04:00
|
|
|
expect(second[:post_actions].first[:conversation][:response][:excerpt]).to match("<img src=")
|
2013-08-19 07:14:26 -04:00
|
|
|
|
2014-02-06 22:11:52 -05:00
|
|
|
posts, users = FlagQuery.flagged_posts_report(admin, "", 1)
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(posts.count).to eq(1)
|
2013-08-19 07:14:26 -04:00
|
|
|
|
2014-02-06 22:11:52 -05:00
|
|
|
# chuck post in category a mod can not see and make sure its missing
|
|
|
|
category = Fabricate(:category)
|
2017-07-27 21:20:09 -04:00
|
|
|
category.set_permissions(admins: :full)
|
2014-02-06 22:11:52 -05:00
|
|
|
category.save
|
|
|
|
post2.topic.category_id = category.id
|
|
|
|
post2.topic.save
|
|
|
|
|
|
|
|
posts, users = FlagQuery.flagged_posts_report(moderator, "")
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(posts.count).to eq(1)
|
2013-08-19 07:14:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|