@@ -178,7 +178,7 @@ module Decidim::Meetings
178
178
end
179
179
180
180
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 )
182
182
allow ( Decidim . traceability )
183
183
. to receive ( :create! )
184
184
. and_return ( meeting )
@@ -232,6 +232,92 @@ module Decidim::Meetings
232
232
233
233
subject . call
234
234
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
235
321
end
236
322
end
237
323
end
0 commit comments