DEV: Enhance post action handler events (#23027)
This commit is contained in:
parent
993ed10cf0
commit
6801cf34cc
|
@ -279,9 +279,9 @@ class PostActionCreator
|
||||||
if post_action
|
if post_action
|
||||||
case @post_action_type_id
|
case @post_action_type_id
|
||||||
when *PostActionType.notify_flag_type_ids
|
when *PostActionType.notify_flag_type_ids
|
||||||
DiscourseEvent.trigger(:flag_created, post_action)
|
DiscourseEvent.trigger(:flag_created, post_action, self)
|
||||||
when PostActionType.types[:like]
|
when PostActionType.types[:like]
|
||||||
DiscourseEvent.trigger(:like_created, post_action)
|
DiscourseEvent.trigger(:like_created, post_action, self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,13 @@ class PostActionDestroyer
|
||||||
GivenDailyLike.decrement_for(@destroyed_by.id)
|
GivenDailyLike.decrement_for(@destroyed_by.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
case @post_action_type_id
|
||||||
|
when *PostActionType.notify_flag_type_ids
|
||||||
|
DiscourseEvent.trigger(:flag_destroyed, post_action, self)
|
||||||
|
when PostActionType.types[:like]
|
||||||
|
DiscourseEvent.trigger(:like_destroyed, post_action, self)
|
||||||
|
end
|
||||||
|
|
||||||
UserActionManager.post_action_destroyed(post_action)
|
UserActionManager.post_action_destroyed(post_action)
|
||||||
PostActionNotifier.post_action_deleted(post_action)
|
PostActionNotifier.post_action_deleted(post_action)
|
||||||
result.success = true
|
result.success = true
|
||||||
|
|
|
@ -122,6 +122,28 @@ RSpec.describe PostActionCreator do
|
||||||
|
|
||||||
expect(Notification.where(notification_type: Notification.types[:liked]).exists?).to eq(false)
|
expect(Notification.where(notification_type: Notification.types[:liked]).exists?).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "triggers the right flag events" do
|
||||||
|
events = DiscourseEvent.track_events { PostActionCreator.create(user, post, :inappropriate) }
|
||||||
|
event_names = events.map { |event| event[:event_name] }
|
||||||
|
expect(event_names).to include(:flag_created)
|
||||||
|
expect(event_names).not_to include(:like_created)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "triggers the right like events" do
|
||||||
|
events = DiscourseEvent.track_events { PostActionCreator.create(user, post, :like) }
|
||||||
|
event_names = events.map { |event| event[:event_name] }
|
||||||
|
expect(event_names).to include(:like_created)
|
||||||
|
expect(event_names).not_to include(:flag_created)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "sends the right event arguments" do
|
||||||
|
events = DiscourseEvent.track_events { PostActionCreator.create(user, post, :like) }
|
||||||
|
event = events.find { |e| e[:event_name] == :like_created }
|
||||||
|
expect(event.present?).to eq(true)
|
||||||
|
expect(event[:params].first).to be_instance_of(PostAction)
|
||||||
|
expect(event[:params].second).to be_instance_of(PostActionCreator)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "flags" do
|
describe "flags" do
|
||||||
|
|
|
@ -44,6 +44,30 @@ RSpec.describe PostActionDestroyer do
|
||||||
expect(stats_message).to be_present
|
expect(stats_message).to be_present
|
||||||
expect(stats_message.data[:like_count]).to eq(0)
|
expect(stats_message.data[:like_count]).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "triggers the right flag events" do
|
||||||
|
PostActionCreator.new(user, post, PostActionType.types[:inappropriate]).perform
|
||||||
|
events =
|
||||||
|
DiscourseEvent.track_events { PostActionDestroyer.destroy(user, post, :inappropriate) }
|
||||||
|
event_names = events.map { |event| event[:event_name] }
|
||||||
|
expect(event_names).to include(:flag_destroyed)
|
||||||
|
expect(event_names).not_to include(:like_destroyed)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "triggers the right like events" do
|
||||||
|
events = DiscourseEvent.track_events { PostActionDestroyer.destroy(user, post, :like) }
|
||||||
|
event_names = events.map { |event| event[:event_name] }
|
||||||
|
expect(event_names).to include(:like_destroyed)
|
||||||
|
expect(event_names).not_to include(:flag_destroyed)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "sends the right event arguments" do
|
||||||
|
events = DiscourseEvent.track_events { PostActionDestroyer.destroy(user, post, :like) }
|
||||||
|
event = events.find { |e| e[:event_name] == :like_destroyed }
|
||||||
|
expect(event.present?).to eq(true)
|
||||||
|
expect(event[:params].first).to be_instance_of(PostAction)
|
||||||
|
expect(event[:params].second).to be_instance_of(PostActionDestroyer)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when post action doesn’t exist" do
|
context "when post action doesn’t exist" do
|
||||||
|
|
Loading…
Reference in New Issue