Skip to content

Commit

Permalink
remove fixture and use fabricator to match other specs after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
njaeggi committed Aug 22, 2024
1 parent 8443e2b commit efe7adc
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 33 deletions.
9 changes: 5 additions & 4 deletions app/controllers/people/membership_invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class People::MembershipInvoicesController < ApplicationController
def create
authorize!(:create, ExternalInvoice::SacMembership)
authorize!(:create, external_invoice)

invoice_form.attributes = invoice_form_params

Expand All @@ -34,16 +34,17 @@ def invoice_form_params
end

def create_invoice
@external_invoice ||= ExternalInvoice::SacMembership.create(
external_invoice.assign_attributes(
state: :draft,
year: invoice_form.reference_date.year,
issued_at: invoice_form.invoice_date,
sent_at: invoice_form.send_date,
person: person,
link: Group.find(invoice_form.section_id)
)
).save!
end

def external_invoice = @external_invoice ||= ExternalInvoice::SacMembership.new(person: person)

def enqueue_membership_invoice_job
membership_invoice = @external_invoice.build_membership_invoice(invoice_form.discount, invoice_form.new_entry, invoice_form.reference_date)

Expand Down
4 changes: 0 additions & 4 deletions spec/abilities/json_api/external_invoice_ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
group: groups(:bluemlisalp_funktionaere)).person
end

before do
external_invoices(:external_invoice_draft).destroy!
end

context "index" do
def accessible_by(user)
ExternalInvoice.accessible_by(described_class.new(user))
Expand Down
4 changes: 0 additions & 4 deletions spec/abilities/token_ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

let(:ability) { TokenAbility.new(token) }

before do
external_invoices(:external_invoice_draft).destroy!
end

describe "index_external_invoices on Group" do
context :root do
let(:token) { service_tokens(:permitted_root_layer_token) }
Expand Down
9 changes: 0 additions & 9 deletions spec/fixtures/external_invoices.yml

This file was deleted.

20 changes: 13 additions & 7 deletions spec/jobs/create_membership_invoice_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@
let(:person) { people(:mitglied) }
let(:person_with_years) { context.people_with_membership_years.find(person.id) }
let(:abacus_client) { instance_double(Invoices::Abacus::Client) }
let(:external_invoice_draft) { Fabricate(:external_invoice, person: person,
link: section,
state: :draft,
issued_at: date,
sent_at: date,
year: date.year,
type: "ExternalInvoice::SacMembership") }

before do
SacMembershipConfig.update_all(valid_from: 2020)
SacSectionMembershipConfig.update_all(valid_from: 2020)
Role.update_all(delete_on: date.end_of_year)
person.update!(zip_code: 3600, town: "Thun")
end

context "mitglied" do
subject(:job) { CreateMembershipInvoiceJob.new(external_invoices(:external_invoice_draft).id, date, 0, false) }
subject(:job) { CreateMembershipInvoiceJob.new(external_invoice_draft.id, date, 0, false) }

it "creates an invoice for membership" do
allow_any_instance_of(CreateMembershipInvoiceJob).to receive(:client).and_return(abacus_client)
Expand Down Expand Up @@ -156,10 +162,10 @@
context "for main family person" do
let(:person) { people(:familienmitglied) }

subject(:job) { CreateMembershipInvoiceJob.new(external_invoices(:external_invoice_draft).id, date, 0, false) }
subject(:job) { CreateMembershipInvoiceJob.new(external_invoice_draft.id, date, 0, false) }

it "creates an invoice for family membership" do
external_invoices(:external_invoice_draft).update!(person: person)
external_invoice_draft.update!(person: person)
allow_any_instance_of(CreateMembershipInvoiceJob).to receive(:client).and_return(abacus_client)
expect(abacus_client).to receive(:create).with(:subject, Hash).and_return({id: 7})
expect(abacus_client).to receive(:create).with(:address, Hash)
Expand Down Expand Up @@ -251,18 +257,18 @@
context "for secondary family person" do
let(:person) { people(:familienmitglied_kind) }

subject(:job) { CreateMembershipInvoiceJob.new(external_invoices(:external_invoice_draft).id, date, 0, false) }
subject(:job) { CreateMembershipInvoiceJob.new(external_invoice_draft.id, date, 0, false) }

it "creates no invoice for family membership" do
external_invoices(:external_invoice_draft).update!(person: person)
external_invoice_draft.update!(person: person)
allow_any_instance_of(CreateMembershipInvoiceJob).to receive(:client).and_return(abacus_client)
expect(abacus_client).not_to receive(:create)

job.perform
end

it "creates invoice for additional membership" do
external_invoices(:external_invoice_draft).update!(person: person)
external_invoice_draft.update!(person: person)
allow_any_instance_of(CreateMembershipInvoiceJob).to receive(:client).and_return(abacus_client)

groups(:bluemlisalp_ortsgruppe_ausserberg).sac_section_membership_configs.create!(
Expand Down
8 changes: 7 additions & 1 deletion spec/models/external_invoice/sac_membership_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
describe ExternalInvoice::SacMembership do
let(:date) { Date.new(2023, 1, 1) }
let(:person) { Person.with_membership_years("people.*", date).find_by(id: people(:mitglied).id) }
let(:external_invoice_draft) { external_invoices(:external_invoice_draft) }
let(:external_invoice_draft) { Fabricate(:external_invoice, person: people(:mitglied),
link: groups(:bluemlisalp),
state: :draft,
issued_at: date,
sent_at: date,
year: date.year,
type: "ExternalInvoice::SacMembership") }

context "memberships link to stammsektion" do
it "gets correct memberships" do
Expand Down
4 changes: 0 additions & 4 deletions spec/resources/external_invoice/reads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
]
end

before do
external_invoices(:external_invoice_draft).destroy!
end

it "serializes expected attributes" do
render
data = jsonapi_data[0]
Expand Down

0 comments on commit efe7adc

Please sign in to comment.