Skip to content

Commit e3527f5

Browse files
committed
fix commands, add tests
1 parent 7e05927 commit e3527f5

File tree

5 files changed

+91
-1
lines changed

5 files changed

+91
-1
lines changed

decidim-meetings/app/commands/decidim/meetings/admin/publish_meeting.rb

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def send_notification
6161

6262
def schedule_upcoming_meeting_notification
6363
return if meeting.start_time < Time.zone.now
64+
return unless meeting.reminder_enabled
6465

6566
checksum = Decidim::Meetings::UpcomingMeetingNotificationJob.generate_checksum(meeting)
6667
reminder_hours = (meeting.send_reminders_before_hours.presence || Decidim::Meetings.upcoming_meeting_notification.in_hours).to_i

decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def start_time_changed?
101101

102102
def schedule_upcoming_meeting_notification
103103
return if meeting.start_time < Time.zone.now
104+
return unless meeting.reminder_enabled
104105

105106
checksum = Decidim::Meetings::UpcomingMeetingNotificationJob.generate_checksum(meeting)
106107
reminder_hours = (meeting.send_reminders_before_hours.presence || Decidim::Meetings.upcoming_meeting_notification.in_hours).to_i

decidim-meetings/app/commands/decidim/meetings/create_meeting.rb

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def create_meeting!
7777

7878
def schedule_upcoming_meeting_notification
7979
return if meeting.start_time < Time.zone.now
80+
return unless meeting.reminder_enabled
8081

8182
checksum = Decidim::Meetings::UpcomingMeetingNotificationJob.generate_checksum(meeting)
8283
reminder_hours = (meeting.send_reminders_before_hours.presence || Decidim::Meetings.upcoming_meeting_notification.in_hours).to_i

decidim-meetings/app/commands/decidim/meetings/update_meeting.rb

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def start_time_changed?
9797

9898
def schedule_upcoming_meeting_notification
9999
return if meeting.start_time < Time.zone.now
100+
return unless meeting.reminder_enabled
100101

101102
checksum = Decidim::Meetings::UpcomingMeetingNotificationJob.generate_checksum(meeting)
102103
reminder_hours = (meeting.send_reminders_before_hours.presence || Decidim::Meetings.upcoming_meeting_notification.in_hours).to_i

decidim-meetings/spec/commands/create_meeting_spec.rb

+87-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ module Decidim::Meetings
178178
end
179179

180180
it "schedules a upcoming meeting notification job 48h before start time" do
181-
meeting = instance_double(Meeting, id: 1, start_time: start_time, participatory_space: participatory_process)
181+
meeting = instance_double(Meeting, id: 1, start_time: start_time, participatory_space: participatory_process, reminder_enabled: true, send_reminders_before_hours: nil)
182182
allow(Decidim.traceability)
183183
.to receive(:create!)
184184
.and_return(meeting)
@@ -232,6 +232,92 @@ module Decidim::Meetings
232232

233233
subject.call
234234
end
235+
236+
context "when scheduling a meeting reminder" do
237+
let(:meeting) do
238+
instance_double(
239+
Meeting,
240+
id: 1,
241+
start_time: start_time,
242+
participatory_space: participatory_process,
243+
reminder_enabled: reminder_enabled,
244+
send_reminders_before_hours: send_reminders_before_hours
245+
)
246+
end
247+
248+
before do
249+
allow(Decidim.traceability).to receive(:create!).and_return(meeting)
250+
allow(meeting).to receive(:valid?)
251+
allow(meeting).to receive(:publish!)
252+
allow(meeting).to receive(:to_signed_global_id).and_return "gid://Decidim::Meetings::Meeting/1"
253+
allow(UpcomingMeetingNotificationJob).to receive(:generate_checksum).and_return "1234"
254+
allow(Decidim::EventsManager).to receive(:publish).and_return(true)
255+
end
256+
257+
context "when reminder is enabled and custom hours are set" do
258+
let(:send_reminders_before_hours) { 48 }
259+
let(:reminder_enabled) { true }
260+
261+
it "schedules a notification job 48h before start time" do
262+
expect(UpcomingMeetingNotificationJob)
263+
.to receive_message_chain(:set, :perform_later) # rubocop:disable RSpec/MessageChain
264+
.with(set: start_time - 48.hours).with(1, "1234")
265+
266+
subject.call
267+
end
268+
end
269+
270+
context "when reminder is enabled but hours are zero" do
271+
let(:send_reminders_before_hours) { 0 }
272+
let(:reminder_enabled) { true }
273+
274+
it "schedules a notification job using the default value" do
275+
default_value = Decidim::Meetings.upcoming_meeting_notification.in_hours
276+
277+
expect(UpcomingMeetingNotificationJob)
278+
.to receive_message_chain(:set, :perform_later) # rubocop:disable RSpec/MessageChain
279+
.with(set: start_time - default_value.hours).with(1, "1234")
280+
281+
subject.call
282+
end
283+
end
284+
285+
context "when reminder is enabled but hours are nil" do
286+
let(:send_reminders_before_hours) { nil }
287+
let(:reminder_enabled) { true }
288+
289+
it "schedules a notification job using the default value" do
290+
default_value = Decidim::Meetings.upcoming_meeting_notification.in_hours
291+
292+
expect(UpcomingMeetingNotificationJob)
293+
.to receive_message_chain(:set, :perform_later) # rubocop:disable RSpec/MessageChain
294+
.with(set: start_time - default_value.hours).with(1, "1234")
295+
296+
subject.call
297+
end
298+
end
299+
300+
context "when reminder is disabled" do
301+
let(:send_reminders_before_hours) { 48 }
302+
let(:reminder_enabled) { false }
303+
304+
it "does not schedule a notification job" do
305+
expect(UpcomingMeetingNotificationJob).not_to receive(:set)
306+
subject.call
307+
end
308+
end
309+
310+
context "when start time is in the past" do
311+
let(:start_time) { 2.days.ago }
312+
let(:reminder_enabled) { true }
313+
let(:send_reminders_before_hours) { 48 }
314+
315+
it "does not schedule a notification job" do
316+
expect(UpcomingMeetingNotificationJob).not_to receive(:set)
317+
subject.call
318+
end
319+
end
320+
end
235321
end
236322
end
237323
end

0 commit comments

Comments
 (0)