DEV: Add test for post notices. (#7352)

This commit is contained in:
Dan Ungureanu 2019-04-10 22:06:27 +03:00 committed by GitHub
parent 689c7f5410
commit 47c50d9a95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -371,7 +371,7 @@ class PostSerializer < BasicPostSerializer
def include_post_notice_type?
return false if !scope.user || !scope.user.id || scope.user.id == object.user_id ||
!object.user || object.user.anonymous? || object.user.bot? ||
!object.user || object.user.anonymous? || object.user.bot? || object.user.staged ||
!scope.user.has_trust_level?(SiteSetting.min_post_notice_tl)
post_notice_type.present?

View File

@ -191,7 +191,7 @@ describe PostSerializer do
PostSerializer.new(post, scope: Guardian.new(user), root: false).as_json
end
it "will not show for poster and TL2+ users" do
it "is visible for TL2+ users (except poster)" do
expect(json_for_user(nil)[:post_notice_type]).to eq(nil)
expect(json_for_user(user)[:post_notice_type]).to eq(nil)
@ -203,6 +203,22 @@ describe PostSerializer do
expect(json_for_user(user_tl1)[:post_notice_type]).to eq("returning")
expect(json_for_user(user_tl2)[:post_notice_type]).to eq("returning")
end
it "is visible when created by anonymous, bots and staged users" do
expect(json_for_user(user_tl2)[:post_notice_type]).to eq("returning")
post.user = nil
expect(json_for_user(user_tl2)[:post_notice_type]).to eq(nil)
post.user = AnonymousShadowCreator.get(user)
expect(json_for_user(user_tl2)[:post_notice_type]).to eq(nil)
post.user = Discourse.system_user
expect(json_for_user(user_tl2)[:post_notice_type]).to eq(nil)
post.user = Fabricate(:staged)
expect(json_for_user(user_tl2)[:post_notice_type]).to eq(nil)
end
end
end