Skip to content

Commit

Permalink
test print invoice button under ACTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
abdellani committed Oct 3, 2023
1 parent 8ed2cc1 commit 49a5382
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion spec/system/admin/orders/invoices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

let(:user) { create(:user) }
let(:product) { create(:simple_product) }
let(:distributor) { create(:distributor_enterprise, owner: user, charges_sales_tax: true) }
let(:distributor) {
create(:distributor_enterprise, owner: user, charges_sales_tax: true, abn: "123456")
}
let(:order_cycle) do
create(:simple_order_cycle, name: 'One', distributors: [distributor],
variants: [product.variants.first])
Expand Down Expand Up @@ -104,6 +106,67 @@
end
end

describe 'printing invoices' do
context 'when the order has no invoices' do
it 'creates an invoice for the order' do
expect(order.invoices.count).to eq 0
page.find("#links-dropdown", text: "ACTIONS").click
click_link "Print Invoice"
new_window = windows.last
page.within_window new_window do
expect(order.invoices.count).to eq 1
end
invoice = order.invoices.first
expect(invoice.cancelled).to eq false
expect(invoice.number).to eq 1
end
end

context 'when the order has an invoice' do
let!(:latest_invoice){ create(:invoice, order:, number: 1, cancelled: false) }
context 'changes require regenerating' do
let(:new_note){ 'new note' }
before do
order.update!(note: new_note)
end

it 'updates the lastest invoice for the order' do
expect(order.invoices.count).to eq 1
page.find("#links-dropdown", text: "ACTIONS").click
click_link "Print Invoice"
new_window = windows.last
page.within_window new_window do
expect(order.invoices.count).to eq 1
end
expect(latest_invoice.reload.presenter.note).to eq new_note
expect(latest_invoice.reload.cancelled).to eq false
end
end
context 'changes require generating a new invoice' do
before do
order.line_items.first.update!(quantity: 2)
end

it 'creates a new invoice for the order' do
expect(order.invoices.count).to eq 1
page.find("#links-dropdown", text: "ACTIONS").click
click_link "Print Invoice"
new_window = windows.last
page.within_window new_window do
expect(order.invoices.count).to eq 2
end
expect(latest_invoice.reload.cancelled).to eq true
expect(latest_invoice.presenter.sorted_line_items.first.quantity).to eq 1

new_invoice = order.invoices.first # first invoice is the latest
expect(new_invoice.cancelled).to eq false
expect(new_invoice.number).to eq 2
expect(new_invoice.presenter.sorted_line_items.first.quantity).to eq 2
end
end
end
end

describe 'listing invoices' do
let(:date){ Time.current.to_date }

Expand Down

0 comments on commit 49a5382

Please sign in to comment.