Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

map date_alert reasons in API

ulfertsfbb58254b036
diff --git a/lib/api/v3/notifications/notification_representer.rb b/lib/api/v3/notifications/notification_representer.rb
index 9ab126fcf68..64e782320f9 100644
--- a/lib/api/v3/notifications/notification_representer.rb
+++ b/lib/api/v3/notifications/notification_representer.rb
@@ -34,14 +34,22 @@ module API
include API::Decorators::LinkedResource
extend API::Decorators::PolymorphicResource
- self_link title_getter: ->(*) {}
+ self_link title: false
property :id
property :read_ian,
as: :readIAN
- property :reason
+ property :reason,
+ getter: ->(*) do
+ case reason
+ when 'date_alert_start_date', 'date_alert_due_date'
+ 'dateAlert'
+ else
+ reason
+ end
+ end
date_time_property :created_at
diff --git a/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb b/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb
index 45f0081b49b..dabe40359d9 100644
--- a/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/notifications/notification_representer_rendering_spec.rb
@@ -103,8 +103,26 @@ describe ::API::V3::Notifications::NotificationRepresenter, 'rendering' do
let(:value) { notification.id }
end
- it_behaves_like 'property', :reason do
- let(:value) { notification.reason }
+ describe 'reason' do
+ (Notification::REASONS.keys - %i[date_alert_start_date date_alert_due_date]).each do |notification_reason|
+ context "for a #{notification_reason} reason" do
+ let(:reason) { notification_reason }
+
+ it_behaves_like 'property', :reason do
+ let(:value) { notification_reason }
+ end
+ end
+ end
+
+ %i[date_alert_start_date date_alert_due_date].each do |notification_reason|
+ context "for a #{notification_reason} reason" do
+ let(:reason) { notification_reason }
+
+ it_behaves_like 'property', :reason do
+ let(:value) { 'dateAlert' }
+ end
+ end
+ end
end
it_behaves_like 'datetime property', :createdAt do