From 540d8c7f0d29c12673ec5a7afabc2eeb11a069e5 Mon Sep 17 00:00:00 2001
From: Niklas <68543592+njaeggi@users.noreply.github.com>
Date: Thu, 26 Sep 2024 11:48:43 +0200
Subject: [PATCH] Include managers as well in case the child creates
participation (#86)
* Include managers as well in case the child creates participation
* Add spec
* Remove changes to participations controller
* Add spec to address list
---
.../event/participations_controller_spec.rb | 59 ++++++++++++++-----
spec/domain/mail_relay/address_list_spec.rb | 8 +++
2 files changed, 53 insertions(+), 14 deletions(-)
diff --git a/spec/controllers/event/participations_controller_spec.rb b/spec/controllers/event/participations_controller_spec.rb
index f1fcd29..8651a10 100644
--- a/spec/controllers/event/participations_controller_spec.rb
+++ b/spec/controllers/event/participations_controller_spec.rb
@@ -39,21 +39,52 @@
let(:pending_dj_handlers) { Delayed::Job.all.pluck(:handler) }
let(:user) { people(:bottom_member) }
- it "sends confirmation mail when manager registers managed" do
- PeopleManager.create!(manager_id: people(:top_leader).id, managed_id: user.id)
- course.update!(waiting_list: false, maximum_participants: 2, participant_count: 1, automatic_assignment: true)
-
- expect do
- post :create, params: {group_id: group.id, event_id: course.id, event_participation: {person_id: user.id}}
- expect(assigns(:participation)).to be_valid
- end.to change { Delayed::Job.count }
-
- expect(pending_dj_handlers).to be_one { |h| h =~ /Event::ParticipationNotificationJob/ }
- expect(pending_dj_handlers).to be_one { |h| h =~ /Event::ParticipationConfirmationJob/ }
+ context "confirmation mails" do
+ context "as manager" do
+ before do
+ PeopleManager.create!(manager_id: people(:top_leader).id, managed_id: user.id)
+ course.update!(waiting_list: false, maximum_participants: 2, participant_count: 1, automatic_assignment: true)
+ end
+
+ it "sends confirmation mail when registering child" do
+ expect do
+ post :create, params: {group_id: group.id, event_id: course.id, event_participation: {person_id: user.id}}
+ expect(assigns(:participation)).to be_valid
+ end.to change { Delayed::Job.count }
+
+ expect(pending_dj_handlers).to be_one { |h| h =~ /Event::ParticipationNotificationJob/ }
+ expect(pending_dj_handlers).to be_one { |h| h =~ /Event::ParticipationConfirmationJob/ }
+
+ expect(flash[:notice])
+ .to include "Teilnahme von #{user} in Eventus wurde erfolgreich erstellt. Bitte überprüfe die Kontaktdaten und passe diese gegebenenfalls an."
+ expect(flash[:warning]).to be_nil
+ end
+ end
- expect(flash[:notice])
- .to include "Teilnahme von #{user} in Eventus wurde erfolgreich erstellt. Bitte überprüfe die Kontaktdaten und passe diese gegebenenfalls an."
- expect(flash[:warning]).to be_nil
+ context "as child" do
+ before do
+ sign_in(user)
+ Fabricate(:role, type: Group::TopGroup::Leader.sti_name, person: user, group: groups(:top_group))
+ PeopleManager.create!(manager_id: people(:top_leader).id, managed_id: user.id)
+ course.update!(waiting_list: false, maximum_participants: 2, participant_count: 1, automatic_assignment: true)
+ end
+
+ it "sends confirmation mail to manager when child does not have email" do
+ user.update!(email: nil)
+
+ expect do
+ post :create, params: {group_id: group.id, event_id: course.id, event_participation: {person_id: user.id}}
+ expect(assigns(:participation)).to be_valid
+ end.to change { Delayed::Job.count }
+
+ expect(pending_dj_handlers).to be_one { |h| h =~ /Event::ParticipationNotificationJob/ }
+ expect(pending_dj_handlers).to be_one { |h| h =~ /Event::ParticipationConfirmationJob/ }
+
+ expect(flash[:notice])
+ .to include "Teilnahme von #{user} in Eventus wurde erfolgreich erstellt. Bitte überprüfe die Kontaktdaten und passe diese gegebenenfalls an."
+ expect(flash[:warning]).to be_nil
+ end
+ end
end
it 'sets participation state to applied' do
diff --git a/spec/domain/mail_relay/address_list_spec.rb b/spec/domain/mail_relay/address_list_spec.rb
index 281d2d1..c6d18a9 100644
--- a/spec/domain/mail_relay/address_list_spec.rb
+++ b/spec/domain/mail_relay/address_list_spec.rb
@@ -69,6 +69,14 @@
new_manager.email
])
end
+
+ it 'contains only manager emails when managed has no email' do
+ managed.update!(email: nil)
+
+ expect(entries(managed)).to match_array([
+ manager.email
+ ])
+ end
end
def entries(people = Person.all, labels = [])