Sha256: 1e80415badc2ab5ef270d6901dbf3f1f75da1bc38bf45d582adbcefc9d29452e

Contents?: true

Size: 1.94 KB

Versions: 35

Compression:

Stored size: 1.94 KB

Contents

require 'test_helper'

module Workarea
  module Insights
    class StarSearchesTest < TestCase
      def test_generate_weekly!
        create_search_by_week(
          query_id: 'foo',
          searches_percentile: 100,
          reporting_on: Time.current.last_week,
          conversion_rate: 0.1
        )
        create_search_by_week(
          query_id: 'bar',
          searches_percentile: 90,
          reporting_on: Time.current.last_week,
          conversion_rate: 0.2
        )
        create_search_by_week(
          query_id: 'baz',
          searches_percentile: 100,
          reporting_on: Time.current.last_week,
          conversion_rate: 0.01
        )
        create_search_by_week(
          query_id: 'qoo',
          searches_percentile: 100,
          reporting_on: Time.current.last_week,
          conversion_rate: 0.02
        )

        StarSearches.generate_weekly!
        assert_equal(1, StarSearches.count)

        star_searches = StarSearches.first
        assert_equal(1, star_searches.results.size)
        assert_equal('foo', star_searches.results.first['query_id'])
        assert_equal(0.1, star_searches.results.first['conversion_rate'])
      end

      def test_avg_conversion_rate_of_top_two_searches_deciles
        create_search_by_week(
          searches_percentile: 100,
          reporting_on: Time.current.last_week,
          conversion_rate: 0.1
        )
        create_search_by_week(
          searches_percentile: 90,
          reporting_on: Time.current.last_week,
          conversion_rate: 0.2
        )
        create_search_by_week(
          searches_percentile: 90,
          reporting_on: 2.weeks.ago,
          conversion_rate: 0.01
        )
        create_search_by_week(
          searches_percentile: 80,
          reporting_on: Time.current.last_week,
          conversion_rate: 0.01
        )

        assert_in_delta(0.15, StarSearches.avg_conversion_rate_of_top_two_searches_deciles)
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
workarea-core-3.4.25 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.24 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.23 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.22 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.21 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.5.0.beta.1 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.20 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.19 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.18 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.17 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.16 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.15 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.14 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.13 test/models/workarea/insights/star_searches_test.rb
workarea-core-3.4.12 test/models/workarea/insights/star_searches_test.rb