Skip to content

Commit

Permalink
more fixes around tests
Browse files Browse the repository at this point in the history
  • Loading branch information
annvelents committed Jan 9, 2025
1 parent 3455e51 commit aed1f2c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(section:)

def call
deselect_for_organization
result.section = section
result
end

Expand All @@ -23,7 +24,6 @@ def deselect_for_organization
InvoiceCustomSectionSelection.where(
organization_id: organization.id, invoice_custom_section_id: section.id
).destroy_all
result.section = section
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

it "sets skip_invoice_custom_sections to false" do
service.call
expect(customer.reload.skip_invoice_custom_sections).to be_false
expect(customer.reload.skip_invoice_custom_sections).to be false
expect(customer.selected_invoice_custom_sections.ids).to match_array([])
expect(customer.applicable_invoice_custom_sections.ids).to match_array(customer.organization.selected_invoice_custom_sections.ids)
end
Expand All @@ -100,7 +100,7 @@

it "sets skip_invoice_custom_sections to true" do
service.call
expect(customer.reload.skip_invoice_custom_sections).to be_true
expect(customer.reload.skip_invoice_custom_sections).to be true
expect(customer.selected_invoice_custom_sections).to be_empty
expect(customer.applicable_invoice_custom_sections).to be_empty
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

RSpec.describe Organizations::DeselectInvoiceCustomSectionService, type: :service do
describe '#call' do
subject(:service_result) { described_class.call(section:) }
subject(:service_call) { described_class.call(section:) }

let(:organization) { create(:organization) }
let(:section) { create(:invoice_custom_section, organization:) }

context 'when section is not selected for the organization' do
it 'deselects the section for the organization' do
expect(service_result).to be_success
result = service_call
expect(result).to be_success
expect(result.section.selected_for_organization?).to be false
end
end

Expand All @@ -21,9 +23,9 @@
end

it 'deselects the section for the organization' do
expect { service_result }.to change(organization.selected_invoice_custom_sections, :count).by(-1)
expect { service_call }.to change(organization.selected_invoice_custom_sections, :count).by(-1)
expect(organization.invoice_custom_sections).to include(section)
expect(service_result).to be_success
expect(section.selected_for_organization?).to be false
end
end
end
Expand Down

0 comments on commit aed1f2c

Please sign in to comment.