Skip to content

Commit

Permalink
Fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
njaeggi committed Aug 20, 2024
1 parent ab73807 commit cc73964
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 40 deletions.
8 changes: 4 additions & 4 deletions app/domain/invoices/abacus/membership_invoice_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def memberships
elsif @invoice.link.layer_group == member.new_entry_role&.layer_group
[member.membership_from_role(member.new_entry_role, main: true)]
elsif (member.new_additional_section_membership_roles + member.additional_membership_roles).map(&:layer_group).include?(@invoice.link.layer_group)

else
[]
end
Expand All @@ -68,7 +68,7 @@ def memberships
def member
@member ||= Invoices::SacMemberships::Member.new(person, context)
end

def context
@context ||= Invoices::SacMemberships::Context.new(@date)
end
Expand All @@ -81,8 +81,8 @@ def handle_invoice_generation_error(message)
category: "rechnungen",
subject: @invoice
)
return false
false
end
end
end
end
end
22 changes: 10 additions & 12 deletions app/jobs/create_membership_invoice_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ def initialize(invoice, date, new_entry = false, discount = nil)
end

def perform
begin
precondition_checker = Invoices::Abacus::MembershipInvoiceGenerator.new(person, @date, @invoice, @new_entry, @discount)
precondition_checker = Invoices::Abacus::MembershipInvoiceGenerator.new(person, @date, @invoice, @new_entry, @discount)

if precondition_checker.invoice_possible?
membership_invoice = precondition_checker.generate_membership_invoice

subject_interface.transmit(subject)
@invoice.update!(total: membership_invoice.total)
sales_order_interface.create(sales_order(membership_invoice))
end
rescue => e
handle_invoice_generation_error(e.message)
raise e
if precondition_checker.invoice_possible?
membership_invoice = precondition_checker.generate_membership_invoice

subject_interface.transmit(subject)
@invoice.update!(total: membership_invoice.total)
sales_order_interface.create(sales_order(membership_invoice))
end
rescue => e
handle_invoice_generation_error(e.message)
raise e
end

def error(_job, exception, payload = parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
let(:date) { Date.new(2023, 1, 1) }
let(:person) { Person.with_membership_years("people.*", date).find_by(id: people(:mitglied).id) }


before do
SacMembershipConfig.update_all(valid_from: 2020)
SacSectionMembershipConfig.update_all(valid_from: 2020)
Expand All @@ -20,13 +19,12 @@
end

context "invoice precontions" do

subject { described_class.new(person, date, external_invoices(:external_invoice_draft), false, 0) }

it "invoice isnt possible if person has no role on invoice link section" do
allow_any_instance_of(Invoices::Abacus::MembershipInvoice).to receive(:invoice?).and_return(true)
external_invoices(:external_invoice_draft).update!(link: groups(:matterhorn_mitglieder))

subject.invoice_possible?

expect(external_invoices(:external_invoice_draft).state).to eq("error")
Expand All @@ -36,7 +34,7 @@

it "invoice isnt possible if membership invoice? returns false" do
allow_any_instance_of(Invoices::Abacus::MembershipInvoice).to receive(:invoice?).and_return(false)

subject.invoice_possible?

expect(external_invoices(:external_invoice_draft).state).to eq("error")
Expand All @@ -46,7 +44,7 @@

it "invoice is possible if all condition are met" do
allow_any_instance_of(Invoices::Abacus::MembershipInvoice).to receive(:invoice?).and_return(true)

subject.invoice_possible?
end
end
Expand Down
30 changes: 11 additions & 19 deletions spec/jobs/create_membership_invoice_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@
expect(abacus_client).to receive(:create).with(:sales_order, data).and_return({sales_order_id: 19})
expect(abacus_client).to receive(:endpoint).with(:sales_order, Hash)
expect(abacus_client).to receive(:request).with(:post, String, Hash)

job.perform

expect(person.reload.abacus_subject_key).to eq(7)

invoice = ExternalInvoice.last
expect(invoice.abacus_sales_order_key).to eq(19)
expect(invoice.issued_at).to eq(date)
Expand All @@ -119,11 +119,11 @@
expect(abacus_client).to receive(:create).with(:communication, Hash)
expect(abacus_client).to receive(:create).with(:customer, Hash)
expect(abacus_client).to receive(:create).with(:sales_order, Hash).and_raise(ex)

expect { job.perform }.to raise_error(RestClient::Exception)

expect(person.reload.abacus_subject_key).to eq(7)

invoice = ExternalInvoice.last
expect(invoice.abacus_sales_order_key).to eq(nil)
expect(invoice.state).to eq("error")
Expand All @@ -140,11 +140,11 @@
expect(abacus_client).to receive(:create).with(:communication, Hash)
expect(abacus_client).to receive(:create).with(:customer, Hash)
expect(abacus_client).to receive(:create).with(:sales_order, Hash).and_raise(ex)

expect { job.perform }.to raise_error(RestClient::Exception)

expect(person.reload.abacus_subject_key).to eq(7)

invoice = ExternalInvoice.last
expect(invoice.abacus_sales_order_key).to eq(nil)
expect(invoice.state).to eq("error")
Expand All @@ -155,7 +155,7 @@
it "handles people without membership in job again" do
allow_any_instance_of(Invoices::Abacus::MembershipInvoice).to receive(:invoice?).and_return(true)
external_invoices(:external_invoice_draft).update!(link: groups(:matterhorn_mitglieder))

job.perform

expect(external_invoices(:external_invoice_draft).state).to eq("error")
Expand Down Expand Up @@ -391,12 +391,4 @@
expect(invoice.person).to eq(person)
end
end

context "neuanmeldung" do

end

context "zusatzsektionen"


end
end

0 comments on commit cc73964

Please sign in to comment.