Skip to content

Commit

Permalink
MembershipManager is called with layer not neuanmeldungs group (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaierhofer committed Dec 11, 2024
1 parent c93e893 commit dfcfcb1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/domain/invoices/sac_memberships/membership_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def update_role_to_stammsektion_mitglied(person)
end

def update_roles_to_zusatzsektion_mitglied(person)
role = person.sac_membership.neuanmeldung_zusatzsektion_roles.find_by(group_id: group.id)
role = person.sac_membership.neuanmeldung_zusatzsektion_roles.find { |role| role.layer_group == group.layer_group }
if role
role.destroy
create_mitglied_zusatzsektion_role(person)
Expand Down Expand Up @@ -95,7 +95,7 @@ def neuanmeldung_stammsektion?
end

def neuanmeldung_zusatzsektion?
person.sac_membership.neuanmeldung_zusatzsektion_roles.first&.layer_group == group.layer_group
person.sac_membership.neuanmeldung_zusatzsektion_roles.any? { |role| role.layer_group == group.layer_group }
end

def family_main_person?
Expand Down
26 changes: 21 additions & 5 deletions spec/domain/invoices/sac_memberships/membership_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
let(:familienmitglied2_person) { people(:familienmitglied2) }
let(:familienmitglied_kind_person) { people(:familienmitglied_kind) }

let(:bluemlisalp) { groups(:bluemlisalp) }
let(:matterhorn) { groups(:matterhorn) }

before do
Role.update_all(end_on: Time.zone.today.end_of_year)
end

it "does not fail if running without any actual work todo" do
manager = described_class.new(Fabricate(:person), groups(:bluemlisalp_mitglieder), end_of_next_year.year)
manager = described_class.new(Fabricate(:person), bluemlisalp, end_of_next_year.year)
expect { manager.update_membership_status }.not_to raise_error
end

Expand All @@ -47,7 +50,7 @@ def updated_roles_count
end

context "adult" do
subject { described_class.new(mitglied_person, groups(:bluemlisalp_mitglieder), end_of_next_year.year) }
subject { described_class.new(mitglied_person, bluemlisalp, end_of_next_year.year) }

it "updates end_on" do
expect(updated_roles_count).to eq(2)
Expand All @@ -73,7 +76,7 @@ def updated_roles_count
end

context "family" do
subject { described_class.new(familienmitglied_person, groups(:bluemlisalp_mitglieder), end_of_next_year.year) }
subject { described_class.new(familienmitglied_person, bluemlisalp, end_of_next_year.year) }

it "updates end_on for all family member roles" do
expect(updated_roles_count).to eq(6)
Expand Down Expand Up @@ -141,7 +144,7 @@ def updated_roles_count
group: groups(:bluemlisalp_neuanmeldungen_nv))
end

subject { described_class.new(familienmitglied_person, groups(:bluemlisalp_neuanmeldungen_nv), end_of_next_year.year) }
subject { described_class.new(familienmitglied_person, bluemlisalp, end_of_next_year.year) }

it "creates stammsektion role" do
subject.update_membership_status
Expand Down Expand Up @@ -174,14 +177,27 @@ def updated_roles_count
group: groups(:matterhorn_neuanmeldungen_nv))
end

subject { described_class.new(mitglied_person, groups(:matterhorn_neuanmeldungen_nv), end_of_next_year.year) }
subject { described_class.new(mitglied_person, matterhorn, end_of_next_year.year) }

it "creates zusatzsektions role" do
expect { subject.update_membership_status }.to have_enqueued_mail(Invoices::SacMembershipsMailer, :confirmation).once

expect(mitglied_person.roles.count).to eq(2)
expect(mitglied_person.sac_membership.zusatzsektion_roles.first.end_on).to eq(end_of_next_year)
end

it "only creates zusatzsektion for layer in question if two roles exist" do
Fabricate(Group::SektionsNeuanmeldungenNv::NeuanmeldungZusatzsektion.sti_name.to_sym,
person: mitglied_person,
beitragskategorie: :adult,
group: groups(:bluemlisalp_ortsgruppe_ausserberg_neuanmeldungen_nv))

expect { subject.update_membership_status }.to have_enqueued_mail(Invoices::SacMembershipsMailer, :confirmation).once

expect(mitglied_person.roles.count).to eq(3)
expect(mitglied_person.sac_membership.zusatzsektion_roles.count).to eq 1
expect(mitglied_person.sac_membership.zusatzsektion_roles.first.group.layer_group).to eq matterhorn
end
end

context "family" do
Expand Down

0 comments on commit dfcfcb1

Please sign in to comment.