require 'fileutils'
require 'test/unit'
require_relative '../lib/report'

class ReportTest < Test::Unit::TestCase
  def test_a_report_is_generated
    filename = 'fake_file.xlsx'
    output_location = 'files/finished'

    File.delete(output_location + filename) if File.exist?(output_location + filename)

    Report.run(filename, sample_data, 899, output_location)

    assert File.exist?('files/finished/fake_file_done.xlsx')

    FileUtils.rm('files/finished/fake_file_done.xlsx')
  end


  def sample_data
    [{account_id: 21989,
      contract_id: 500074,
      upc: 1234567890123,
      amount: -50,
      currency: "USD",
      activity_year: 2022,
      activity_month: 8,
      apply_year: 2022,
      apply_month: 8,
      adjustment_type: "Physical Coop",
      comment: nil,
      distribution_type: "Digital",
      reasons: ["UPC must be 12 characters long"],
      record_id: nil},
     {account_id: 21990,
      contract_id: 500074,
      upc: 1234567890123,
      amount: -50,
      currency: "USD",
      activity_year: 2022,
      activity_month: 8,
      apply_year: 2022,
      apply_month: 8,
      adjustment_type: "Label Expenditure",
      comment: nil,
      distribution_type: "Digital",
      reasons: ["UPC must be 12 characters long"],
      record_id: nil},
     {account_id: 21992,
      contract_id: 500074,
      upc: 1234567890123,
      amount: -50,
      currency: "EUR",
      activity_year: 2022,
      activity_month: 8,
      apply_year: 2022,
      apply_month: 8,
      adjustment_type: "Account Expense",
      comment: nil,
      distribution_type: "Digital",
      reasons:
       ["UPC must be 12 characters long", "Adjustment type is not supported"],
      record_id: nil},
     {account_id: 21989,
      contract_id: 500074,
      upc: 1234567890123,
      amount: -50,
      currency: "EUR",
      activity_year: 2022,
      activity_month: 8,
      apply_year: 2023,
      apply_month: 8,
      adjustment_type: "Account Expense",
      comment: nil,
      distribution_type: "Digital",
      reasons:
       ["UPC must be 12 characters long", "Adjustment type is not supported"],
      record_id: nil},
     {account_id: 21989,
      contract_id: 500074,
      upc: nil,
      amount: 50,
      currency: "EUR",
      activity_year: 2022,
      activity_month: 8,
      apply_year: 2022,
      apply_month: 8,
      adjustment_type: "Advertising",
      comment: nil,
      distribution_type: nil,
      reasons: [],
      record_id: 69268}]
  end

end

