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.15 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.36 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.14 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.35 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.13 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.34 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.12 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.33 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.11 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.10 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.32 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.9 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.31 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.8 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.30 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.7 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.29 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.6 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.4.28 test/integration/workarea/admin/reports_integration_test.rb
workarea-admin-3.5.5 test/integration/workarea/admin/reports_integration_test.rb