<commit_before>require File.expand_path('../../header', __FILE__)

class PackagerTest < TestCase
  def setup
    @packager = ShippingMaterials::Packager.new
  end

  def test_format
    @packager.package(orders) { format :pdf => 'path/to/template' }

    assert_block "Format should have type and template" do
      @packager.format == :pdf && @packager.template == 'path/to/template'
    end
  end

  def test_packaging_multiple_groups
    @packager.package(orders) do
      group 'canada_standard_post'
      group 'united_states_ups'
      group 'international_ups_expedited'
    end

    assert_equal 3, @packager.groups.size,
                "Multiple groups are borked"
  end

  def test_group_filter
    @packager.package orders do
      group 'canada_standard_post' do
        filter { shipping_method == 'std' && country == 'CA' }
      end
    end

    assert_block "Shipping method didn't filter" do
      @packager.groups.first.objects.size > 0
    end
  end

  def test_group_labels
    @packager.package orders do
      group 'canada_standard_post' do
        filter { shipping_method == 'std' && country == 'CA' }
        labels(:extension => 'csv', :headers => true)
      end
    end

    assert_block "Label options are not getting set" do
      labels = @packager.groups.first.labels
      labels.first.extension == 'csv' && labels.first.headers?
    end
  end

  def test_should_accept_multiple_row_maps_in_different_contexts
    @packager.package orders do
      group 'canada_standard_post' do
        filter { shipping_method == 'std' && country == 'CA' }
        labels :extension => 'csv', :headers => true do
          row :order_id => :id,
              :name     => :name,
              :static_fields => 'Use a string'

          row :line_items => [ :id, :name, :quantity, :price ]
        end
      end
    end

    assert_equal [:object, :line_items],
                @packager.groups.first.labels.first.row_maps.keys,
                "Row maps aren't getting keyed"
  end
end<commit_msg>Use template in Packager test<commit_after>require File.expand_path('../../header', __FILE__)

class PackagerTest < TestCase
  def setup
    @packager = ShippingMaterials::Packager.new
  end

  def test_format
    @packager.package(orders) { format :pdf => 'path/to/template' }

    assert_block "Format should have type and template" do
      @packager.format == :pdf && @packager.template == 'path/to/template'
    end
  end

  def test_packaging_multiple_groups
    @packager.package(orders) do
      group 'canada_standard_post'
      group 'united_states_ups'
      group 'international_ups_expedited'
    end

    assert_equal 3, @packager.groups.size,
                "Multiple groups are borked"
  end

  def test_group_filter
    @packager.package orders do
      group 'canada_standard_post' do
        filter { shipping_method == 'std' && country == 'CA' }
      end
    end

    assert_block "Shipping method didn't filter" do
      @packager.groups.first.objects.size > 0
    end
  end

  def test_group_labels
    @packager.package orders do
      group 'canada_standard_post' do
        filter { shipping_method == 'std' && country == 'CA' }
        labels(:extension => 'csv', :headers => true)
      end
    end

    assert_block "Label options are not getting set" do
      labels = @packager.groups.first.labels
      labels.first.extension == 'csv' && labels.first.headers?
    end
  end

  def test_should_accept_multiple_row_maps_in_different_contexts
    ShippingMaterial.config do |config|
      config.save_path 'test/files/'
    end

    @packager.package orders do
      packing_slips pdf: './test/files/template.mustache'

      group 'canada_standard_post' do
        filter { shipping_method == 'std' && country == 'CA' }
        labels :extension => 'csv', :headers => true do
          row :order_id => :id,
              :name     => :name,
              :static_fields => 'Use a string'

          row :line_items => [ :id, :name, :quantity, :price ]
        end
      end
    end

    assert_equal [:object, :line_items],
                @packager.groups.first.labels.first.row_maps.keys,
                "Row maps aren't getting keyed"
  end
end
{'fraction_non_alphanumeric': 0.10235658176624614, 'fraction_numerical': 0.0009521542489883361, 'mean_word_length': 2.5761702127659576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '1775388', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1252, 'n_words': 326}