Sha256: ca1efcd17cfc2065cac780c9dd3202e7bca0eb5d2121de6443629bc4bb77b977

Contents?: true

Size: 1.75 KB

Versions: 62

Compression:

Stored size: 1.75 KB

Contents

require 'test_helper'

module Workarea
  module Admin
    class ReportsIntegrationTest < Workarea::IntegrationTest
      include Admin::IntegrationTest

      def test_exporting
        Metrics::ProductByDay.inc(key: { product_id: 'foo' }, orders: 1)
        Metrics::ProductByDay.inc(key: { product_id: 'bar' }, orders: 2)

        assert_difference 'ActionMailer::Base.deliveries.size' do
          post admin.export_report_path,
            params: {
              export: {
                report_type: 'sales_by_product',
                report_params: { sort_by: 'orders' },
                emails: %w(bcrouse@workarea.com foo@workarea.com)
              }
            }
        end

        assert_redirected_to(admin.root_path)
        assert(flash[:success]).present?

        assert_equal(1, Workarea::Reports::Export.count)
        export = Workarea::Reports::Export.first
        assert(export.started_at.present?)
        assert(export.file.present?)
        assert(export.completed_at.present?)

        email = ActionMailer::Base.deliveries.last
        assert_includes(email.bcc, 'bcrouse@workarea.com')
        assert_includes(email.bcc, 'foo@workarea.com')
        email.parts.each do |part|
          assert_includes(part.body, admin.download_report_url(export))
        end

        get admin.download_report_url(export)
        assert_equal(response.body, export.file.data)
      end

      def test_exports_with_errors
        post admin.export_report_path, params: { export: {} }
        assert_redirected_to(admin.root_path)
        assert(flash[:error].present?)

        post admin.export_report_path,
          params: { export: { report_type: 'sales_by_product' } }
        refute(response.redirect?)
        assert(flash[:error].present?)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.26 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.45 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.25 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.23 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.44 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.22 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.43 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.21 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.42 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.20 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.41 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.19 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.40 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.18 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.39 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.17 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.38 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.16 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.37 test/integration/workarea/admin/reports_integration_test.rb