Include detailsSchemas in the NotificationCollectionRepresenter

pull/11437/head
Dombi Attila 2 years ago
parent 1557d5fe3c
commit 1d53e91a69
  1. 5
      lib/api/v3/notifications/notification_collection_representer.rb
  2. 7
      lib/api/v3/values/schemas/value_schema_factory.rb
  3. 5
      spec/lib/api/v3/notifications/notification_collection_representer_spec.rb

@ -30,6 +30,11 @@ module API
module V3
module Notifications
class NotificationCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection
property :detailsSchemas,
getter: ->(*) { ::API::V3::Values::Schemas::ValueSchemaFactory.all },
exec_context: :decorator,
embedded: true
def initialize(models, self_link:, current_user:, query: {}, page: nil, per_page: nil, groups: nil)
super

@ -29,6 +29,7 @@
module API::V3::Values::Schemas
module ValueSchemaFactory
extend ::API::V3::Utilities::PathHelper
SUPPORTED = %w(start_date due_date).freeze
module_function
@ -41,10 +42,14 @@ module API::V3::Values::Schemas
self_link: api_v3_paths.value_schema(property))
end
def all
SUPPORTED.map { |property| self.for(property) }
end
def supported?(property)
# This is but a stub. Currently, only 'start_date' and 'due_date'
# need to be supported so this simple approach works.
%w(start_date due_date).include?(property)
SUPPORTED.include?(property)
end
def model_for(property)

@ -79,6 +79,11 @@ describe ::API::V3::Notifications::NotificationCollectionRepresenter do
it_behaves_like 'offset-paginated APIv3 collection', 3, 'notifications', 'Notification'
it 'renders the available detailsSchemas' do
details_schemas = ::API::V3::Values::Schemas::ValueSchemaFactory.all
expect(subject).to be_json_eql(details_schemas.to_json).at_path('_embedded/detailsSchemas')
end
context 'when passing groups' do
let(:groups) do
[

Loading…
Cancel
Save