FIX: Missing event user notifications (#418)

* FIX: Fix for missing event user notifications

* implemented tests for corrected bug

* stree issues
This commit is contained in:
Juan David Martínez Cubillos 2023-07-14 16:40:23 -05:00 committed by GitHub
parent 3552bbf2a3
commit 3778169086
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 1 deletions

View File

@ -17,7 +17,7 @@ module DiscoursePostEvent
event = Event.find(params[:id])
guardian.ensure_can_act_on_discourse_post_event!(event)
invites = Array(params.permit(invites: [])[:invites])
users = Invitee.extract_uniq_usernames(invites)
users = User.real.where(username: invites)
users.each { |user| event.create_notification!(user, event.post) }

View File

@ -213,6 +213,7 @@ module DiscoursePostEvent
topic_id: post.topic_id,
post_number: post.post_number,
data: {
user_id: user.id,
topic_title: self.name || post.topic.title,
display_username: post.user.username,
message: message,

View File

@ -17,6 +17,7 @@ describe DiscoursePostEvent::Event do
describe "topic custom fields callback" do
let(:user) { Fabricate(:user, admin: true) }
let!(:notified_user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic, user: user) }
let!(:first_post) { Fabricate(:post, topic: topic) }
let(:second_post) { Fabricate(:post, topic: topic) }
@ -24,6 +25,20 @@ describe DiscoursePostEvent::Event do
let!(:ends_at) { "2020-04-24 16:15:00" }
let!(:alt_starts_at) { "2020-04-24 14:14:25" }
let!(:alt_ends_at) { "2020-04-24 19:15:25" }
let(:event) do
Event.create!(
id: first_post.id,
original_starts_at: Time.now + 1.hours,
original_ends_at: Time.now + 2.hours,
)
end
let(:late_event) do
Event.create!(
id: first_post.id,
original_starts_at: Time.now - 10.hours,
original_ends_at: Time.now - 8.hours,
)
end
describe "#after_commit[:create, :update]" do
context "when a post event has been created" do
@ -63,6 +78,22 @@ describe DiscoursePostEvent::Event do
expect(second_post.topic.custom_fields).to be_blank
end
end
describe "notify an user" do
describe "before the event starts" do
it "does notify the user" do
expect { event.create_notification!(notified_user, first_post) }.to change {
Notification.count
}.by(1)
end
end
describe "after the event starts" do
it "doesn't notify the user" do
expect { late_event.create_notification!(notified_user, first_post) }.not_to change {
Notification.count
}
end
end
end
end
context "when a post event has been updated" do