Sha256: 704a7351eca09bd15e3ebd3fc619ff0a1bee023ec9d7cf7326bee97b6c15ce23

Contents?: true

Size: 1.07 KB

Versions: 34

Compression:

Stored size: 1.07 KB

Contents

require 'test_helper'

module Workarea
  class KeepProductIndexFreshTest < TestCase
    include SearchIndexing

    setup :set_config
    teardown :unset_config

    def set_config
      @current = Workarea.config.stale_products_size
      Workarea.config.stale_products_size = 1
    end

    def unset_config
      Workarea.config.stale_products_size = @current
    end

    def test_indexes_never_indexed_products
      assert_equal(0, Search::Storefront.count)

      3.times { create_product }
      KeepProductIndexFresh.new.perform

      assert_equal(1, Search::Storefront.count)
    end

    def test_indexes_stale_products
      product_1 = create_product
      product_2 = create_product
      product_3 = create_product

      IndexProduct.perform(product_1)
      IndexProduct.perform(product_2)
      IndexProduct.perform(product_3)

      current_last_indexed_at = product_1.last_indexed_at

      travel_to(Time.current + 1.second)
      KeepProductIndexFresh.new.perform

      product_1.reload
      assert(product_1.last_indexed_at > current_last_indexed_at)
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.45 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.44 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.43 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.42 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.41 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.40 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.39 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.38 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.37 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.36 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.35 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.34 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.33 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.32 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.31 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.30 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.29 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.28 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.27 test/workers/workarea/keep_product_index_fresh_test.rb
workarea-core-3.4.26 test/workers/workarea/keep_product_index_fresh_test.rb