Sha256: c101d17f70760342ce782e6feea479e469a62d035d05630cc6a9d230850042ed

Contents?: true

Size: 1.87 KB

Versions: 34

Compression:

Stored size: 1.87 KB

Contents

require 'test_helper'

module Workarea
  class ExportReportTest < TestCase
    setup :add_product_sales_data

    def add_product_sales_data
      Metrics::ProductByDay.inc(key: { product_id: 'foo' }, orders: 1)
      Metrics::ProductByDay.inc(key: { product_id: 'bar' }, orders: 2)
      create_product(id: 'foo')
    end

    def test_persistence
      Workarea.with_config do |config|
        config.reports_max_results = 1
        csv = CSV.new(Tempfile.new)
        export = ExportReport.new(Reports::SalesByProduct.new, csv)

        export.save!
        assert_equal(2, export.collection.count)

        export.destroy!
        assert_equal(0, export.collection.count)
      end
    end

    def test_csv_construction
      Workarea.with_config do |config|
        config.reports_max_results = 1

        csv = CSV.new(Tempfile.new)
        export = ExportReport.new(
          Reports::SalesByProduct.new(sort_by: 'orders', sort_direction: 'desc'),
          csv
        )

        export.perform!
        results = csv.tap(&:rewind).read

        assert_equal(3, results.size)
        assert_equal(7, results.first.size)
        assert_equal('_id', results.first[0])
        assert_equal('orders', results.first[1])
        assert_equal(7, results.second.size)
        assert_equal('bar', results.second[0])
        assert_equal('2', results.second[1])
        assert_equal(7, results.third.size)
        assert_equal('foo', results.third[0])
        assert_equal('1', results.third[1])

        assert_equal(0, export.collection.count)

        csv = CSV.new(Tempfile.new)
        export = ExportReport.new(
          Reports::SalesByProduct.new(sort_by: 'orders', sort_direction: 'asc'),
          csv
        )

        export.perform!
        results = csv.tap(&:rewind).read
        assert_equal('foo', results.second[0])
        assert_equal('bar', results.third[0])
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.45 test/services/workarea/export_report_test.rb
workarea-core-3.4.44 test/services/workarea/export_report_test.rb
workarea-core-3.4.43 test/services/workarea/export_report_test.rb
workarea-core-3.4.42 test/services/workarea/export_report_test.rb
workarea-core-3.4.41 test/services/workarea/export_report_test.rb
workarea-core-3.4.40 test/services/workarea/export_report_test.rb
workarea-core-3.4.39 test/services/workarea/export_report_test.rb
workarea-core-3.4.38 test/services/workarea/export_report_test.rb
workarea-core-3.4.37 test/services/workarea/export_report_test.rb
workarea-core-3.4.36 test/services/workarea/export_report_test.rb
workarea-core-3.4.35 test/services/workarea/export_report_test.rb
workarea-core-3.4.34 test/services/workarea/export_report_test.rb
workarea-core-3.4.33 test/services/workarea/export_report_test.rb
workarea-core-3.4.32 test/services/workarea/export_report_test.rb
workarea-core-3.4.31 test/services/workarea/export_report_test.rb
workarea-core-3.4.30 test/services/workarea/export_report_test.rb
workarea-core-3.4.29 test/services/workarea/export_report_test.rb
workarea-core-3.4.28 test/services/workarea/export_report_test.rb
workarea-core-3.4.27 test/services/workarea/export_report_test.rb
workarea-core-3.4.26 test/services/workarea/export_report_test.rb