From 856d17c51062d0f672105582bc5fec5a6144c012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jirka=20Hut=C3=A1rek?= Date: Fri, 27 Feb 2026 18:26:50 +0100 Subject: [PATCH] Handle missing fields --- app/models/notification/event_payload.rb | 15 +++++++++--- .../notification/push_target/web_test.rb | 24 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/models/notification/event_payload.rb b/app/models/notification/event_payload.rb index e39cde9d4..b296f7252 100644 --- a/app/models/notification/event_payload.rb +++ b/app/models/notification/event_payload.rb @@ -27,9 +27,17 @@ class Notification::EventPayload < Notification::DefaultPayload when "card_sent_back_to_triage" "Moved back to Maybe? by #{event.creator.name}" when "card_board_changed" - "Moved to #{new_board_name} by #{event.creator.name}" + if new_board_name.present? + "Moved to #{new_board_name} by #{event.creator.name}" + else + "Moved by #{event.creator.name}" + end when "card_title_changed" - "Renamed to #{new_title} by #{event.creator.name}" + if new_title.present? + "Renamed to #{new_title} by #{event.creator.name}" + else + "Renamed by #{event.creator.name}" + end when "card_postponed" "Moved to Not Now by #{event.creator.name}" when "card_auto_postponed" @@ -74,7 +82,8 @@ class Notification::EventPayload < Notification::DefaultPayload end def new_board_name - event.particulars.dig("particulars", "new_board") + event.particulars.dig("particulars", "new_board") || + event.particulars.dig("particulars", "new_collection") end def new_title diff --git a/test/models/notification/push_target/web_test.rb b/test/models/notification/push_target/web_test.rb index 6892fb100..26ad80cc8 100644 --- a/test/models/notification/push_target/web_test.rb +++ b/test/models/notification/push_target/web_test.rb @@ -101,6 +101,18 @@ class Notification::PushTarget::WebTest < ActiveSupport::TestCase Notification::PushTarget::Web.new(@notification).process end + test "payload for board change falls back when board name is missing" do + event = events(:logo_published) + event.update!(action: "card_board_changed", particulars: {}) + @notification.update!(source: event) + + @web_push_pool.expects(:queue).once.with do |payload, _| + payload[:body] == "Moved by #{event.creator.name}" + end + + Notification::PushTarget::Web.new(@notification).process + end + test "payload for title change includes new title" do event = events(:logo_published) event.update!(action: "card_title_changed", particulars: { "particulars" => { "old_title" => "Old Title", "new_title" => "New Title" } }) @@ -113,6 +125,18 @@ class Notification::PushTarget::WebTest < ActiveSupport::TestCase Notification::PushTarget::Web.new(@notification).process end + test "payload for title change falls back when title is missing" do + event = events(:logo_published) + event.update!(action: "card_title_changed", particulars: {}) + @notification.update!(source: event) + + @web_push_pool.expects(:queue).once.with do |payload, _| + payload[:body] == "Renamed by #{event.creator.name}" + end + + Notification::PushTarget::Web.new(@notification).process + end + test "payload for postponed includes Not Now" do event = events(:logo_published) event.update!(action: "card_postponed")