DEV: optional include_details param for events' list (#496)

This commit is contained in:
Renato Atilio 2023-12-08 22:01:04 -03:00 committed by GitHub
parent 68a62b1265
commit b9188c4c16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -5,10 +5,13 @@ module DiscoursePostEvent
def index
@events = DiscoursePostEvent::EventFinder.search(current_user, filtered_events_params)
# The detailed serializer is currently not used anywhere in the frontend, but available via API
serializer = params[:include_details] == "true" ? EventSerializer : EventSummarySerializer
render json:
ActiveModel::ArraySerializer.new(
@events,
each_serializer: EventSummarySerializer,
each_serializer: serializer,
scope: guardian,
).as_json
end

View File

@ -247,6 +247,26 @@ module DiscoursePostEvent
[hash_including("id" => event_1.id), hash_including("id" => event_2.id)],
)
end
it "includes events' details when param provided" do
get "/discourse-post-event/events.json?category_id=#{category.id}&include_subcategories=true&include_details=true"
expect(response.status).to eq(200)
events = response.parsed_body["events"]
expect(events.length).to eq(2)
expect(events[0].keys).to include(
"creator",
"sample_invitees",
"watching_invitee",
"stats",
"status",
"can_update_attendance",
"should_display_invitees",
"is_public",
"is_private",
"is_standalone",
)
end
end
end
end