require 'spec_helper'

describe 'prepAccounting.php' do
  before :all do
    @devbox = DevBox.instance
    @script_name = 'prepAccounting.php'
    @s3_helper = S3BucketHelper.new
    @s3_helper.clean_up_emails
  end

  it 'requires a Month and a Year' do
    output = @devbox.run_acc_script(@script_name)
    expect(output).to include('Params Month and Year are required')

    output = @devbox.run_acc_script("#{@script_name} -y 2018")
    expect(output).to include('Params Month and Year are required')

    output = @devbox.run_acc_script("#{@script_name} -m 5")
    expect(output).to include('Params Month and Year are required')
  end

  it 'refuses any extra params' do
    output = @devbox.run_acc_script("#{@script_name} -m 5 -y 2018 -e extra_param")
    expect(output).to include("Usage: #{@script_name}")
  end

  it 'prepares Accounting Run' do
    @devbox.run_acc_script("#{@script_name} -m 6 -y 2017")
    email_subject = 'Accounting Pre-Processing'
    EventuallyHelper.eventually do
      @s3_helper.email_by_subject(email_subject) || raise("#{email_subject} email not found")
    end
    email_text = @s3_helper.read_email(@s3_helper.email_by_subject(email_subject))
    expect(email_text).to include('Populated Vendor Contract Snapshot Table')
    expect(email_text).to include('Loaded Currency Exchange Rates')
    expect(email_text).to include('Updated Manual Adjustments')
    expect(email_text).to include('Updated Checkspaid')
  end
end
