Skip to content

Commit

Permalink
Set address of family members during self-registration (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchr authored Sep 5, 2024
1 parent 2ff8916 commit 2744a4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 5 additions & 9 deletions app/models/wizards/signup/sektion_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SektionWizard < Wizards::RegisterNewUserWizard
]

MIN_ADULT_YEARS = SacCas::Beitragskategorie::Calculator::AGE_RANGE_ADULT.begin
ADDRESS_KEYS = %i[address_care_of street housenumber postbox zip_code town country]

delegate :email, to: :main_email_field
delegate :person_attributes, :birthday, to: :person_fields
Expand Down Expand Up @@ -54,10 +55,9 @@ def operations_valid?
end

def people_attrs
members
.map(&:person_attributes)
.unshift(main_person_attributes)
.map { |attrs| attrs.merge(common_person_attrs) }
main_person_attrs = main_person_attributes.merge(common_person_attrs)
merge_attrs = main_person_attrs.slice(*ADDRESS_KEYS, *common_person_attrs.keys)
members.map { |member| member.person_attributes.merge(merge_attrs) }.unshift(main_person_attrs)
end

def main_person_attributes
Expand All @@ -67,11 +67,7 @@ def main_person_attributes
end

def common_person_attrs
{
self_registration_reason_id:,
privacy_policy_accepted_at:,
household_key: household_key
}.compact_blank
{self_registration_reason_id:, privacy_policy_accepted_at:, household_key:}.compact_blank
end

def register_on = various_fields.register_on_date || Time.zone.today
Expand Down
4 changes: 3 additions & 1 deletion spec/models/wizards/signup/sektion_wizard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def build(params = required_attrs)
expect(max.roles.last.beitragskategorie).to eq "youth"
end

it "creates multiple people and sets household key" do
it "creates multiple people and sets household key and address" do
required_attrs[:family_fields] = {
members_attributes: [
[1, {first_name: "Maxi", last_name: "Muster", birthday: "1.1.2012"}],
Expand All @@ -168,6 +168,8 @@ def build(params = required_attrs)
expect(maxine.household_key).to eq(max.household_key)
expect(maxi.roles.last.beitragskategorie).to eq "family"
expect(maxine.roles.last.beitragskategorie).to eq "family"
expect(maxi.address).to eq(max.address)
expect(maxine.address).to eq(max.address)
end

context "various fields" do
Expand Down

0 comments on commit 2744a4a

Please sign in to comment.