<commit_before>require 'spec_helper'

describe WageSlave::SaveInvoices do

  let(:data) {[
    { due_date: Date.today, name: "<NAME>", description: "No Yelling commission", quantity: 1, unit_amount: 100, account_code: 240 },
    { due_date: Date.today, name: "<NAME>", description: "No Yelling commission", quantity: 1, unit_amount: 100, account_code: 240 },
    { due_date: Date.today, name: "<NAME>", description: "No Yelling commission", quantity: 1, unit_amount: 100, account_code: 240 },
    { due_date: Date.today, name: "<NAME>", description: "No Yelling commission", quantity: 1, unit_amount: 100, account_code: 240 },
    { due_date: Date.today, name: "<NAME>", description: "No Yelling commission", quantity: 1, unit_amount: 100, account_code: 240 },
  ]}

  let(:invoices) {
    WageSlave::BuildInvoices.call data
  }

  before :each do
    WageSlave.configure do | config |
      config.xero = {
        consumer_key: "test",
        consumer_secret: "test",
        pem_file_location: "test",
      }
    end
  end

  it "must be a class" do
    WageSlave::SaveInvoices.must_be_instance_of Class
  end

  it "will attempt to save a batch of Xeroizer invoices" do

    WageSlave
      .configuration
      .xero.Invoice
      .expects(:save_records).with(invoices)

    WageSlave::SaveInvoices.call invoices

  end

  it "will report errors if the records are invalid" do

    invalid_data = data.map { |d| d[:name] = nil }

    # Invalidate invoices
    invoices = WageSlave::BuildInvoices.call data

    invoices.each do | invoice |
      invoice.valid?.must_equal false
    end

    saved_invoices = WageSlave::SaveInvoices.call invoices

    saved_invoices.must_equal false

  end

end<commit_msg>Fix incorrect spec for WageSlave::SaveInvoices<commit_after>require 'spec_helper'

describe WageSlave::SaveInvoices do

  let(:data) {[
    { due_date: Date.today, name: "<NAME>", description: "No Yelling commission", quantity: 1, unit_amount: 100, account_code: 240 },
    { due_date: Date.today, name: "<NAME>", description: "No Yelling commission", quantity: 1, unit_amount: 100, account_code: 240 },
    { due_date: Date.today, name: "<NAME>", description: "No Yelling commission", quantity: 1, unit_amount: 100, account_code: 240 },
    { due_date: Date.today, name: "<NAME>", description: "No Yelling commission", quantity: 1, unit_amount: 100, account_code: 240 },
    { due_date: Date.today, name: "<NAME>", description: "No Yelling commission", quantity: 1, unit_amount: 100, account_code: 240 },
  ]}

  let(:invoices) {
    WageSlave::BuildInvoices.call data
  }

  before :each do
    WageSlave.configure do | config |
      config.xero = {
        consumer_key: "test",
        consumer_secret: "test",
        pem_file_location: "test",
      }
    end
  end

  it "must be a class" do
    WageSlave::SaveInvoices.must_be_instance_of Class
  end

  it "will attempt to save a batch of Xeroizer invoices" do

    WageSlave
      .configuration
      .xero.Invoice
      .expects(:save_records).with(invoices)

    WageSlave::SaveInvoices.call invoices

  end

  it "will report errors if the records are invalid" do

    invalid_data = [{ due_date: Date.today, name: nil, description: "No Yelling commission", quantity: 1, unit_amount: 100, account_code: 240 }]

    # Invalidate invoices
    invoices = WageSlave::BuildInvoices.call invalid_data

    invoices.each do | invoice |
      invoice.valid?.must_equal false
    end

    saved_invoices = WageSlave::SaveInvoices.call invoices

    saved_invoices.must_equal false

  end

end
{'fraction_non_alphanumeric': 0.11260881774782365, 'fraction_numerical': 0.021623139567537208, 'mean_word_length': 3.650130548302872, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1669502', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1148, 'n_words': 321}