Skip to content

A platform for community discussion. Free, open, simple.

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

Dan Ungureanu47c50d9a95d5
diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb
index d70a1062159..635ee446b2d 100644
--- a/app/serializers/post_serializer.rb
+++ b/app/serializers/post_serializer.rb
@@ -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?
diff --git a/spec/serializers/post_serializer_spec.rb b/spec/serializers/post_serializer_spec.rb
index 00c78376de4..4d8af7b0008 100644
--- a/spec/serializers/post_serializer_spec.rb
+++ b/spec/serializers/post_serializer_spec.rb
@@ -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