Skip to content

Commit

Permalink
Configure special course leader role for events api (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
codez committed Nov 21, 2024
1 parent 10b4dcf commit bcd910e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/hitobito_sac_cas/wagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class Wagon < Rails::Engine
EventResource.include SacCas::EventResource
Event::CourseResource.include SacCas::Event::CourseResource
Event::KindResource.include SacCas::Event::KindResource
Person::NameResource.course_leader_role = Event::Course::Role::Leader

## Helpers
EventKindsHelper.prepend SacCas::EventKindsHelper
Expand Down
20 changes: 20 additions & 0 deletions spec/api/events/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,25 @@
expect(d.map(&:id)).not_to be_empty
end
end

context "with include leaders" do
it "includes only leaders" do
course = events(:top_course)
leader = people(:tourenchef)
participation = course.participations.create!(person: leader, active: true)
Event::Course::Role::Leader.create!(participation: participation)
assistant = course.participations.create!(person: people(:familienmitglied), active: true)
Event::Course::Role::AssistantLeader.create!(participation: assistant)

jsonapi_get "/api/events", params: {include: "leaders"}

expect(response.status).to eq(200), response.body

expect(json["data"].first["id"]).to eq(course.id.to_s)
expect(json["data"].first["relationships"]["leaders"]["data"].size).to eq(1)
expect(json["data"].first["relationships"]["leaders"]["data"].first["id"]).to eq(leader.id.to_s)
expect(json["included"].first["id"]).to eq(leader.id.to_s)
end
end
end
end
17 changes: 16 additions & 1 deletion spec/resources/sac_cas/event/course_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require "spec_helper"

describe Event::CourseResource, type: :resource do
let(:event) { events(:closed) }
let(:event) { events(:top_course) }
let(:person) { people(:admin) }
let(:additional_attrs) do
[
Expand Down Expand Up @@ -41,4 +41,19 @@
expect(attrs).to have_key(attr)
end
end

it "includes leaders" do
leader = people(:tourenchef)
participation = event.participations.create!(person: leader, active: true)
Event::Course::Role::Leader.create!(participation: participation)

params[:include] = "leaders"
render
data = jsonapi_data[0]
leaders = data.sideload(:leaders)
expect(leaders.size).to eq(1)
expect(leaders.first.id).to eq(leader.id)
expect(leaders.first.first_name).to eq(leader.first_name)
expect(leaders.first.last_name).to eq(leader.last_name)
end
end

0 comments on commit bcd910e

Please sign in to comment.