require 'test/unit'
require_relative '../lib/adjustments_expenses'
require_relative 'fake_db'
require_relative '../lib/repo'

class AdjustmentsExpensesTest < Test::Unit::TestCase
  def sample_data
    [
      {:account_id=>21989, :contract_id=>500074, :upc=>12345671231,
       :amount=>-50, :currency=>"USD", :activity_year=>2022, :activity_month=>8,
       :apply_year=>2022, :apply_month=>9, :adjustment_type=>"Physical Coop",
       :comment=>nil, :distribution_type=>"Digital",
       :activity_period_id=>284, :apply_period_id=>296, :adjustment_type_id=>78,
       :reasons=>["UPC must be 12 characters long"]},

      {:account_id=>21989, :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",
       :activity_period_id=>284, :apply_period_id=>296, :adjustment_type_id=>65,
       :reasons=> ["UPC must be 12 characters long",
                   "Adjustment type is not supported"]},

      {:account_id=>21989, :contract_id=>500074, :upc=>nil,
       :amount=>50, :currency=>"EUR",:activity_year=>2022,
       :activity_month=>8, :apply_year=>2023, :apply_month=>8,
       :adjustment_type=>"Physical Coop",
       :comment=>nil,
       :activity_period_id=>284, :apply_period_id=>296, :adjustment_type_id=>78,
       :distribution_type=>nil, :reasons=>[]},

      {:account_id=>21989, :contract_id=>500074, :upc=>123456789123,
       :amount=>-87, :currency=>"EUR",:activity_year=>2022,
       :activity_month=>8, :apply_year=>2023, :apply_month=>8,
       :adjustment_type=>"Advertising",
       :comment=>nil,
       :activity_period_id=>284, :apply_period_id=>296, :adjustment_type_id=>62,
       :distribution_type=>'Physical', :reasons=>[]}

     ]
  end

  def test_record_id_returned_for_valid_inserts
    report_rows, _statement_period_id = AdjustmentsExpenses.commit('fake.file', 283, sample_data, FakeDB.new)

    assert_nil     report_rows[0][:record_id]
    assert_not_nil report_rows[2][:record_id]
  end
end

