Sha256: c9e34fb5842334311c4c4326156854033e709f245eacc1a82f124cd2e5225401

Contents?: true

Size: 1.35 KB

Versions: 62

Compression:

Stored size: 1.35 KB

Contents

require 'test_helper'

module Workarea
  class ProcessProductRecommendationsTest < Workarea::TestCase
    def test_processing_recent_orders
      Order.create!(
        placed_at: Time.current,
        items: [
          { product_id: '1', sku: 'SKU' },
          { product_id: '2', sku: 'SKU' }
        ]
      )

      2.times do
        Order.create!(
          placed_at: Time.current,
          items: [
            { product_id: '1', sku: 'SKU' },
            { product_id: '3', sku: 'SKU' }
          ]
        )
      end

      ProcessProductRecommendations.new.perform

      predictor = Recommendation::ProductPredictor.new
      assert_equal(%w(3 2), predictor.similarities_for('1'))
    end

    def test_within_expiration
      Order.create!(
        placed_at: Time.current,
        items: [
          { product_id: '1', sku: 'SKU' },
          { product_id: '2', sku: 'SKU' }
        ]
      )

      travel_to((Workarea.config.recommendation_expiration + 1.day).from_now)

      2.times do
        Order.create!(
          placed_at: Time.current,
          items: [
            { product_id: '1', sku: 'SKU' },
            { product_id: '3', sku: 'SKU' }
          ]
        )
      end

      ProcessProductRecommendations.new.perform

      predictor = Recommendation::ProductPredictor.new
      assert_equal(%w(3), predictor.similarities_for('1'))
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

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