Sha256: ea57c4492a274b03f7294623f0ad99c16af42009a3464875f746a8d24a896976

Contents?: true

Size: 1.55 KB

Versions: 34

Compression:

Stored size: 1.55 KB

Contents

require 'test_helper'

module Workarea
  module Pricing
    class CacheKeyTest < TestCase
      setup :setup_tax_category,
            :setup_discount,
            :setup_product,
            :setup_order,
            :setup_order_item,
            :setup_shipping,
            :setup_pricing,
            :setup_cache_key

      def test_parts
        parts = @cache_key.parts.flatten

        assert_includes(parts, @pricing.cache_key)
        assert_includes(parts, @discount.reload.cache_key)
        assert_includes(parts, @order.cache_key)
        assert_includes(parts, @shipping.cache_key)
        assert_includes(parts, @tax.reload.cache_key)
      end

      def test_to_s
        digest = Digest::SHA1.hexdigest(@cache_key.parts.join('/'))
        assert_equal(@cache_key.to_s, digest)
      end

      private

      def setup_tax_category
        @tax = create_tax_category
      end

      def setup_discount
        @discount = create_order_total_discount(order_total: 1.to_m)
      end

      def setup_order
        @order = create_order
      end

      def setup_order_item
        @order.add_item(sku: @sku, product_id: @product.id)
      end

      def setup_product
        @product = create_product
        @sku = @product.skus.first
      end

      def setup_shipping
        @shipping = create_shipping
      end

      def setup_pricing
        @pricing = Pricing::Sku.find(@sku)
        @request = Request.new(@order, @shipping)
      end

      def setup_cache_key
        @cache_key = CacheKey.new(@order, [@shipping], @request)
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.25 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.24 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.23 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.22 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.21 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.20 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.19 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.18 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.17 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.16 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.15 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.14 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.13 test/models/workarea/pricing/cache_key_test.rb
workarea-core-3.4.12 test/models/workarea/pricing/cache_key_test.rb