<commit_before>require 'spec_helper'

describe Spree::Admin::InvoicesController, type: :controller do
  let(:order) { create(:order_with_totals_and_distribution) }
  let(:user) { create(:admin_user) }

  before do
    allow(controller).to receive(:spree_current_user) { 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 Delayed::PerformableMethod

      expect(Delayed::Job.last.payload_object.method_name).to eq :start_pdf_job_without_delay
    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?).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<commit_msg>Stub default value for other calls to File.exist?<commit_after>require 'spec_helper'

describe Spree::Admin::InvoicesController, type: :controller do
  let(:order) { create(:order_with_totals_and_distribution) }
  let(:user) { create(:admin_user) }

  before do
    allow(controller).to receive(:spree_current_user) { 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 Delayed::PerformableMethod

      expect(Delayed::Job.last.payload_object.method_name).to eq :start_pdf_job_without_delay
    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
{'fraction_non_alphanumeric': 0.10061443932411675, 'fraction_numerical': 0.01152073732718894, 'mean_word_length': 3.208400646203554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3398770', 'n_tokens_mistral': 867, 'n_tokens_neox': 808, 'n_words': 224}