mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
This required a tiny refactoring to enable injecting the renderer. It'll make it easier to later add the relevant specs related to the order balance.
50 lines
1.4 KiB
Ruby
50 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
describe InvoiceRenderer do
|
|
let(:service) { described_class.new }
|
|
let(:order) do
|
|
order = create(:completed_order_with_fees)
|
|
order.bill_address = order.ship_address
|
|
order.save!
|
|
order
|
|
end
|
|
|
|
context 'when invoice_style2 is configured' do
|
|
before { allow(Spree::Config).to receive(:invoice_style2?).and_return(true) }
|
|
|
|
it 'uses the invoice2 template' do
|
|
renderer = instance_double(ApplicationController)
|
|
expect(renderer)
|
|
.to receive(:render_to_string)
|
|
.with(include(template: 'spree/admin/orders/invoice2'))
|
|
|
|
described_class.new(renderer).render_to_string(order)
|
|
end
|
|
|
|
it 'creates a PDF invoice' do
|
|
result = service.render_to_string(order)
|
|
expect(result).to match /^%PDF/
|
|
end
|
|
end
|
|
|
|
context 'when invoice_style2 is not configured' do
|
|
before { allow(Spree::Config).to receive(:invoice_style2?).and_return(false) }
|
|
|
|
it 'uses the invoice template' do
|
|
renderer = instance_double(ApplicationController)
|
|
expect(renderer)
|
|
.to receive(:render_to_string)
|
|
.with(include(template: 'spree/admin/orders/invoice'))
|
|
|
|
described_class.new(renderer).render_to_string(order)
|
|
end
|
|
|
|
it 'creates a PDF invoice' do
|
|
result = service.render_to_string(order)
|
|
expect(result).to match /^%PDF/
|
|
end
|
|
end
|
|
end
|