Sha256: a99388bce84f46d29c3041cce985e6f39d403242ebe9e39af06c354d3bfd10e3

Contents?: true

Size: 1.44 KB

Versions: 62

Compression:

Stored size: 1.44 KB

Contents

require 'test_helper'

module Workarea
  class GenerateInsightsTest < TestCase
    def test_perform_resets_and_appends_last_weeks_aggregation
      travel_to Time.zone.local(2018, 10, 27)

      Metrics::ProductForLastWeek.create!(product_id: 'foo')
      Metrics::ProductForLastWeek.create!(product_id: 'bar')
      Metrics::ProductByDay.inc(key: { product_id: 'foo' }, views: 10)
      Metrics::ProductByDay.inc(key: { product_id: 'bar' }, views: 20)

      travel_to Time.zone.local(2018, 10, 29)
      GenerateInsights.new.perform

      assert_equal(2, Metrics::ProductByWeek.count)
      assert_equal(10, Metrics::ProductForLastWeek.find_by(product_id: 'foo').views)
      assert_equal(20, Metrics::ProductForLastWeek.find_by(product_id: 'bar').views)
    end

    def test_generates_weekly_insights_on_monday
      travel_to Time.zone.local(2018, 10, 27)
      Metrics::ProductByDay.inc(key: { product_id: 'foo' }, views: 10, orders: 10)
      Metrics::ProductByDay.inc(key: { product_id: 'bar' }, views: 15, orders: 5)
      Metrics::ProductByDay.inc(key: { product_id: 'baz' }, views: 20, orders: 1)

      travel_to Time.zone.local(2018, 10, 29)
      GenerateInsights.new.perform

      assert_equal(1, Insights::ProductsToImprove.count)
      assert_equal(1, Insights::ProductsToImprove.first.results.size)

      travel_to Time.zone.local(2018, 10, 30)
      GenerateInsights.new.perform
      assert_equal(1, Insights::ProductsToImprove.count)
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.4.27 test/workers/workarea/generate_insights_test.rb
workarea-core-3.5.4 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.26 test/workers/workarea/generate_insights_test.rb
workarea-core-3.5.3 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.25 test/workers/workarea/generate_insights_test.rb
workarea-core-3.5.2 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.24 test/workers/workarea/generate_insights_test.rb
workarea-core-3.5.1 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.23 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.22 test/workers/workarea/generate_insights_test.rb
workarea-core-3.5.0 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.21 test/workers/workarea/generate_insights_test.rb
workarea-core-3.5.0.beta.1 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.20 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.19 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.18 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.17 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.16 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.15 test/workers/workarea/generate_insights_test.rb
workarea-core-3.4.14 test/workers/workarea/generate_insights_test.rb