Sha256: a8af495fe4f7c1429f8b59519329db7bd6127487178c9bd6c7e3b904c3ae425b

Contents?: true

Size: 1.69 KB

Versions: 37

Compression:

Stored size: 1.69 KB

Contents

require 'test_helper'

module Workarea
  module Admin
    class PricingSkuViewModelTest < Workarea::TestCase
      setup :setup_pricing_sku_and_prices

      def setup_pricing_sku_and_prices
        @sku = PricingSkuViewModel.wrap(
          create_pricing_sku(on_sale: true).tap do |sku|
            sku.prices.create!(
              regular: 4.to_m,
              sale: 1.to_m
            )
            sku.prices.create!(
              regular: 3.to_m,
              sale: 2.to_m
            )
          end
        )
      end

      def test_sell_prices
        assert_equal(@sku.prices.count, @sku.sell_prices.count)
      end

      def test_min_price
        assert_equal(1.to_m, @sku.min_price)

        @sku.update!(on_sale: false)

        assert_equal(3.to_m, @sku.min_price)

        @sku.prices.destroy_all

        assert_nil(@sku.min_price)
      end

      def test_max_price
        assert_equal(2.to_m, @sku.max_price)

        @sku.update!(on_sale: false)

        assert_equal(4.to_m, @sku.max_price)

        @sku.prices.destroy_all

        assert_nil(@sku.min_price)
      end

      def test_show_range?
        assert(@sku.show_range?)

        @sku.prices.last.destroy!

        refute(@sku.show_range?)

        @sku.prices.destroy_all

        refute(@sku.show_range?)
      end

      def test_on_sale?
        assert(@sku.on_sale?)

        @sku.update!(on_sale: false)

        refute(@sku.on_sale?)

        @sku.prices.first.update!(on_sale: true)

        assert(@sku.on_sale?)
      end

      def test_price
        assert_match(/.2\.00 – .1\.00/, @sku.sell_price)

        @sku.update!(on_sale: false)

        assert_match(/.4\.00 – .3\.00/, @sku.sell_price)
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

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