mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
remove InvoicesController#create
This commit is contained in:
@@ -17,32 +17,12 @@ module Spree
|
||||
send_file(invoice_pdf, type: 'application/pdf', disposition: :inline)
|
||||
end
|
||||
|
||||
def create
|
||||
Spree::Order.where(id: params[:order_ids]).find_each do |order|
|
||||
authorize! :invoice, order
|
||||
end
|
||||
invoice_service = BulkInvoiceService.new
|
||||
invoice_service.start_pdf_job(params[:order_ids])
|
||||
|
||||
render json: invoice_service.id, status: :ok
|
||||
end
|
||||
|
||||
def generate
|
||||
@order = Order.find_by(number: params[:order_id])
|
||||
authorize! :invoice, @order
|
||||
OrderInvoiceGenerator.new(@order).generate_or_update_latest_invoice
|
||||
redirect_back(fallback_location: spree.admin_dashboard_path)
|
||||
end
|
||||
|
||||
def poll
|
||||
invoice_id = params[:invoice_id]
|
||||
|
||||
if BulkInvoiceService.new.invoice_created? invoice_id
|
||||
render json: { created: true }, status: :ok
|
||||
else
|
||||
render json: { created: false }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Admin::InvoicesController, type: :controller do
|
||||
let(:order) { create(:order_with_totals_and_distribution) }
|
||||
let(:enterprise_user) { create(:user) }
|
||||
let!(:enterprise) { create(:enterprise, owner: enterprise_user) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { enterprise_user }
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
it "enqueues a job to create a bulk invoice and returns the filename" do
|
||||
expect do
|
||||
spree_post :create, order_ids: [order.id]
|
||||
end.to enqueue_job BulkInvoiceJob
|
||||
end
|
||||
end
|
||||
|
||||
describe "#poll" do
|
||||
let(:invoice_id) { '479186263' }
|
||||
|
||||
context "when the file is available" do
|
||||
it "returns true" do
|
||||
allow(File).to receive(:exist?)
|
||||
allow(File).to receive(:exist?).with("tmp/invoices/#{invoice_id}.pdf").and_return(true)
|
||||
|
||||
spree_get :poll, invoice_id: invoice_id
|
||||
|
||||
expect(response.body).to eq({ created: true }.to_json)
|
||||
expect(response.status).to eq 200
|
||||
end
|
||||
end
|
||||
|
||||
context "when the file is not available" do
|
||||
it "returns false" do
|
||||
spree_get :poll, invoice_id: invoice_id
|
||||
|
||||
expect(response.body).to eq({ created: false }.to_json)
|
||||
expect(response.status).to eq 422
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user