Skip to content

Commit

Permalink
Remove entry fee from zusatzsektion wizard (#1203) (#1243)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaierhofer authored Nov 19, 2024
1 parent 14c4c6e commit 709dd9f
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SectionSignupFeePresenter
delegate :discount_factor, to: :context
attr_reader :beitragskategorie, :section

def initialize(section, beitragskategorie, date = Time.zone.today)
def initialize(section, beitragskategorie, date: Time.zone.today)
@section = section
@beitragskategorie = ActiveSupport::StringInquirer.new(beitragskategorie.to_s)
@context = Context.new(date)
Expand All @@ -45,9 +45,9 @@ def beitragskategorie_label
I18n.t("beitragskategorien.#{beitragskategorie}", scope: i18n_scope)
end

def beitragskategorie_amount
def beitragskategorie_amount(skip_entry_fee: false)
parts = [format_position_amount(:annual_fee)]
if entry_fee.positive?
if entry_fee.positive? && !skip_entry_fee
parts += [translate_position_text(:entry_fee)]
parts += [format_position_amount(:entry_fee)]
end
Expand Down
8 changes: 6 additions & 2 deletions app/models/wizards/memberships/join_zusatzsektion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ def backoffice?
@backoffice
end

def fees_for(beitragskategorie, reference_date)
Invoices::SacMemberships::SectionSignupFeePresenter.new(choose_sektion.group, beitragskategorie, reference_date)
def fees_for(beitragskategorie)
Invoices::SacMemberships::SectionSignupFeePresenter.new(
choose_sektion.group,
beitragskategorie,
date: Time.zone.now.beginning_of_year
)
end

private
Expand Down
8 changes: 6 additions & 2 deletions app/models/wizards/memberships/switch_stammsektion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ def backoffice?
@backoffice
end

def fees_for(beitragskategorie, reference_date)
Invoices::SacMemberships::SectionSignupFeePresenter.new(choose_sektion.group, beitragskategorie, reference_date)
def fees_for(beitragskategorie)
Invoices::SacMemberships::SectionSignupFeePresenter.new(
choose_sektion.group,
beitragskategorie,
date: Time.zone.now.beginning_of_year
)
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/models/wizards/signup/sektion_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def fee
fees_for(beitragskategorie)
end

def fees_for(beitragskategorie, reference_date = Time.zone.today)
Invoices::SacMemberships::SectionSignupFeePresenter.new(group.layer_group, beitragskategorie, reference_date)
def fees_for(beitragskategorie)
Invoices::SacMemberships::SectionSignupFeePresenter.new(group.layer_group, beitragskategorie)
end

private
Expand Down
8 changes: 4 additions & 4 deletions app/views/memberships/join_zusatzsektions/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
= c.with_aside do
.col-md
- if wizard.step(:choose_sektion)&.group
= render 'wizards/signup/section_fee_summary', active: true,
adult: wizard.fees_for(:adult, Time.zone.now.beginning_of_year),
family: wizard.fees_for(:family, Time.zone.now.beginning_of_year),
youth: wizard.fees_for(:youth, Time.zone.now.beginning_of_year)
= render 'wizards/signup/section_fee_summary', active: true, skip_entry_fee: true,
adult: wizard.fees_for(:adult),
family: wizard.fees_for(:family),
youth: wizard.fees_for(:youth)
= render(SelfRegistration::InfosComponent.new)
6 changes: 3 additions & 3 deletions app/views/memberships/switch_stammsektions/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.col-md
- if wizard.step(:choose_sektion)&.group
= render 'wizards/signup/section_fee_summary', active: true,
adult: wizard.fees_for(:adult, Time.zone.now.beginning_of_year),
family: wizard.fees_for(:family, Time.zone.now.beginning_of_year),
youth: wizard.fees_for(:youth, Time.zone.now.beginning_of_year)
adult: wizard.fees_for(:adult),
family: wizard.fees_for(:family),
youth: wizard.fees_for(:youth)
= render(SelfRegistration::InfosComponent.new)
8 changes: 5 additions & 3 deletions app/views/wizards/signup/_section_fee_summary.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
-# Affero General Public License version 3 or later. See the COPYING file at the top-level directory
-# or at https://github.com/hitobito/hitobito.
- amount_args = local_assigns.slice(:skip_entry_fee).to_h

%aside.card{class: ("d-none" unless active)}
.card-body
%h2.card-title=t('.title', section: adult.section)
Expand All @@ -10,10 +12,10 @@
%tbody
%tr
%td= adult.beitragskategorie_label
%td= adult.beitragskategorie_amount
%td= adult.beitragskategorie_amount(**amount_args)
%tr.border-top
%td= family.beitragskategorie_label
%td= family.beitragskategorie_amount
%td= family.beitragskategorie_amount(**amount_args)
%tr.border-top
%td= youth.beitragskategorie_label
%td= youth.beitragskategorie_amount
%td= youth.beitragskategorie_amount(**amount_args)
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@
expect(presenter.beitragskategorie_label).to eq expected_labels[beitragskategorie]
end

it "has identical beitragskategorie_amount all year long" do
travel_to(Date.new(2024, 11)) do
parts = presenter.beitragskategorie_amount.split(" + ")
expect(parts.first).to eq "CHF #{format("%.2f", annual_fee)}"
expect(parts.second).to eq "einmalige Eintrittsgebühr CHF #{format("%.2f", entry_fee)}"
describe "beitragskategorie_amount" do
it "is identical all year long" do
travel_to(Date.new(2024, 11)) do
parts = presenter.beitragskategorie_amount.split(" + ")
expect(parts.first).to eq "CHF #{format("%.2f", annual_fee)}"
expect(parts.second).to eq "einmalige Eintrittsgebühr CHF #{format("%.2f", entry_fee)}"
end
end

it "can exclude entry_fee" do
travel_to(Date.new(2024, 11)) do
parts = presenter.beitragskategorie_amount(skip_entry_fee: true).split(" + ")
expect(parts.first).to eq "CHF #{format("%.2f", annual_fee)}"
expect(parts.second).to be_nil
end
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/features/memberships/join_zusatzsektion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
click_on "Weiter"
expect(page).to have_css "li.active", text: "Bestätigung"
expect(page).to have_content "Beitragskategorien SAC Matterhorn"
expect(page).not_to have_css(".card", text: "einmalige Eintrittsgebühr")
expect do
click_on "Kostenpflichtig bestellen"
expect(page).to have_css "#flash .alert-success",
Expand Down
52 changes: 52 additions & 0 deletions spec/views/wizards/signup/_section_fee_summary.html.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_sac_cas.

require "spec_helper"

describe "wizards/signup/_section_fee_summary.html.haml" do
include FormatHelper
let(:group) { groups(:bluemlisalp) }
let(:adult) { fees_for(:adult) }
let(:family) { fees_for(:family) }
let(:youth) { fees_for(:youth) }

let(:dom) {
Capybara::Node::Simple.new(@rendered)
}

def fees_for(beitragskategorie)
Invoices::SacMemberships::SectionSignupFeePresenter.new(group, beitragskategorie, date: Time.zone.now.beginning_of_year)
end

it "is hidden if not active" do
render locals: {adult:, family:, youth:, active: false}
expect(dom).to have_css "aside.card.d-none"
end

it "is hidden if not active" do
render locals: {adult:, family:, youth:, active: true}
expect(dom).to have_css "aside.card:not(.d-none)"
end

it "renders label and amount" do
render locals: {adult:, family:, youth:, active: true}
expect(dom).to have_css "tr:nth-of-type(1) td:nth-of-type(1)", text: "Einzelmitgliedschaft"
expect(dom).to have_css "tr:nth-of-type(1) td:nth-of-type(2)", text: "CHF 127.00 + einmalige Eintrittsgebühr CHF 20.00"
expect(dom).to have_css "tr:nth-of-type(2) td:nth-of-type(1)", text: "Familienmitgliedschaft"
expect(dom).to have_css "tr:nth-of-type(2) td:nth-of-type(2)", text: "CHF 179.00 + einmalige Eintrittsgebühr CHF 35.00"
expect(dom).to have_css "tr:nth-of-type(3) td:nth-of-type(1)", text: "Jugendmitgliedschaft"
expect(dom).to have_css "tr:nth-of-type(3) td:nth-of-type(2)", text: "CHF 76.00 + einmalige Eintrittsgebühr CHF 15.00"
end

it "renders label and amount without entry fee" do
render locals: {adult:, family:, youth:, active: true, skip_entry_fee: true}
expect(dom).to have_css "tr:nth-of-type(1) td:nth-of-type(1)", text: "Einzelmitgliedschaft"
expect(dom).to have_css "tr:nth-of-type(1) td:nth-of-type(2)", text: "CHF 127.00"
expect(dom).to have_css "tr:nth-of-type(2) td:nth-of-type(1)", text: "Familienmitgliedschaft"
expect(dom).to have_css "tr:nth-of-type(2) td:nth-of-type(2)", text: "CHF 179.00"
expect(dom).to have_css "tr:nth-of-type(3) td:nth-of-type(1)", text: "Jugendmitgliedschaft"
expect(dom).to have_css "tr:nth-of-type(3) td:nth-of-type(2)", text: "CHF 76.00"
end
end

0 comments on commit 709dd9f

Please sign in to comment.