Sha256: 71fc93f823d59ced63520f8e3089d20c920fb12f1cc1aa392b30c2300d9f523a

Contents?: true

Size: 1.97 KB

Versions: 34

Compression:

Stored size: 1.97 KB

Contents

require 'test_helper'

module Workarea
  module Pricing
    class RequestTest < TestCase
      setup :create_request

      def create_request
        @tax = create_tax_category

        @pricing = create_pricing_sku(
          id: 'SKU',
          tax_code: @tax.code,
          prices: [{ regular: 5.to_m }]
        )

        @order = Order.new
        @order.add_item(product_id: 'PRODUCT', sku: 'SKU', quantity: 2)
        @order.save!

        @discount = create_product_discount(promo_codes: ['promo-code'])

        @shipping = Shipping.create!(shipping_service: { name: 'Ground' })

        request = Request.new(@order, @shipping)
        request.run
        request.save!

        @request = Request.new(@order, @shipping)
      end

      def test_request_is_fresh_after_priced
        refute @request.stale?
      end

      def test_saving_with_fresh_cache
        request = Request.new(@order, @shipping)
        refute(request.stale?)

        request.save!
        refute(@order.updated_at_changed?)
        refute(@shipping.updated_at_changed?)
      end

      def test_pricing_breaks_cache
        @pricing.updated_at = Time.current + 1.minute
        @pricing.save

        assert @request.stale?
      end

      def test_discounts_break_cache
        @discount.updated_at = Time.current + 1.minute
        @discount.save

        assert @request.stale?
      end

      def test_adding_promo_code_breaks_cache
        @order.add_promo_code('promo-code')

        assert @request.stale?
      end

      def test_adding_an_order_item_breaks_cache
        @order.add_item(product_id: 'PRODUCT', sku: 'SKU2', quantity: 2)

        assert @request.stale?
      end

      def test_tax_breaks_cache
        @tax.updated_at = Time.current + 1.minute
        @tax.save

        assert @request.stale?
      end

      def test_shipping_service_select_breaks_cache
        @shipping.shipping_service.name = 'Second Day'
        @shipping.save!

        assert @request.stale?
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

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