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.25 test/services/workarea/export_report_test.rb
workarea-core-3.4.24 test/services/workarea/export_report_test.rb
workarea-core-3.4.23 test/services/workarea/export_report_test.rb
workarea-core-3.4.22 test/services/workarea/export_report_test.rb
workarea-core-3.4.21 test/services/workarea/export_report_test.rb
workarea-core-3.4.20 test/services/workarea/export_report_test.rb
workarea-core-3.4.19 test/services/workarea/export_report_test.rb
workarea-core-3.4.18 test/services/workarea/export_report_test.rb
workarea-core-3.4.17 test/services/workarea/export_report_test.rb
workarea-core-3.4.16 test/services/workarea/export_report_test.rb
workarea-core-3.4.15 test/services/workarea/export_report_test.rb
workarea-core-3.4.14 test/services/workarea/export_report_test.rb
workarea-core-3.4.13 test/services/workarea/export_report_test.rb
workarea-core-3.4.12 test/services/workarea/export_report_test.rb