Sha256: 68cd1e2d4d5a1487e18a85885ea54f1465852c7663f5ace5b18a4d2cdfa043a6

Contents?: true

Size: 1.94 KB

Versions: 62

Compression:

Stored size: 1.94 KB

Contents

require 'test_helper'

module Workarea
  module Insights
    class MostDiscountGivenTest < TestCase
      setup :add_data, :time_travel

      def add_data
        Metrics::DiscountByDay.inc(
          key: { discount_id: 'foo' },
          at: Time.zone.local(2018, 10, 27),
          discounts: -10.to_m
        )

        Metrics::DiscountByDay.inc(
          key: { discount_id: 'foo' },
          at: Time.zone.local(2018, 10, 28),
          discounts: -15.to_m
        )

        Metrics::DiscountByDay.inc(
          key: { discount_id: 'foo' },
          at: Time.zone.local(2018, 10, 29),
          discounts: -27.to_m
        )

        Metrics::DiscountByDay.inc(
          key: { discount_id: 'bar' },
          at: Time.zone.local(2018, 10, 27),
          discounts: -11.to_m
        )

        Metrics::DiscountByDay.inc(
          key: { discount_id: 'bar' },
          at: Time.zone.local(2018, 10, 28),
          discounts: -15.to_m
        )

        Metrics::DiscountByDay.inc(
          key: { discount_id: 'bar' },
          at: Time.zone.local(2018, 10, 29),
          discounts: -35.to_m
        )
      end

      def time_travel
        travel_to Time.zone.local(2018, 11, 1)
      end

      def test_generate_monthly!
        MostDiscountGiven.generate_monthly!
        assert_equal(1, MostDiscountGiven.count)

        top_discounts = MostDiscountGiven.first
        assert_equal(2, top_discounts.results.size)
        assert_equal('bar', top_discounts.results.first['discount_id'])
        assert_in_delta(53.982, top_discounts.results.first['percent_of_total'])
        assert_equal('foo', top_discounts.results.second['discount_id'])
        assert_in_delta(46.018, top_discounts.results.second['percent_of_total'])
      end

      def test_find_total_orders
        assert_equal(-113, MostDiscountGiven.find_total_discount)

        Metrics::DiscountByDay.delete_all
        assert_equal(0, MostDiscountGiven.find_total_discount)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

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