Sha256: eb271ef385280624df2f5b0bda5653b36eb3e0cc555c00b86cc34577b62b9cb6

Contents?: true

Size: 1.35 KB

Versions: 54

Compression:

Stored size: 1.35 KB

Contents

require 'test_helper'

module Workarea
  class Shipping
    class ServiceTest < TestCase
      def test_rate_tier_validation
        method = create_shipping_service
        method.rates = [{ price: 1.to_m }, { price: 5.to_m }]

        refute(method.valid?)
        assert(method.errors[:rates].present?)
      end

      def test_find_rate
        shipping_service = create_shipping_service

        rate = shipping_service.rates.first
        assert_equal(rate.id, shipping_service.find_rate.id)
        assert_equal(rate.id, shipping_service.find_rate(3.to_m).id)

        shipping_service =
          create_shipping_service.tap do |method|
            method.rates = []
            method.rates.build(price: 4.to_m, tier_min: 0, tier_max: 5)
            method.rates.build(price: 3.to_m, tier_min: 5, tier_max: 7)
            method.rates.build(price: 2.to_m, tier_min: 7, tier_max: nil)
            method.save!
          end

        assert_equal(4.to_m, shipping_service.find_rate.price)
        assert_equal(4.to_m, shipping_service.find_rate(2.to_m).price)
        assert_equal(4.to_m, shipping_service.find_rate(5.to_m).price)

        assert_equal(3.to_m, shipping_service.find_rate(6.to_m).price)
        assert_equal(3.to_m, shipping_service.find_rate(7.to_m).price)
        assert_equal(2.to_m, shipping_service.find_rate(10.to_m).price)
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
workarea-core-3.5.11 test/models/workarea/shipping/service_test.rb
workarea-core-3.5.10 test/models/workarea/shipping/service_test.rb
workarea-core-3.4.32 test/models/workarea/shipping/service_test.rb
workarea-core-3.5.9 test/models/workarea/shipping/service_test.rb
workarea-core-3.4.31 test/models/workarea/shipping/service_test.rb
workarea-core-3.5.8 test/models/workarea/shipping/service_test.rb
workarea-core-3.4.30 test/models/workarea/shipping/service_test.rb
workarea-core-3.5.7 test/models/workarea/shipping/service_test.rb
workarea-core-3.4.29 test/models/workarea/shipping/service_test.rb
workarea-core-3.5.6 test/models/workarea/shipping/service_test.rb
workarea-core-3.4.28 test/models/workarea/shipping/service_test.rb
workarea-core-3.5.5 test/models/workarea/shipping/service_test.rb
workarea-core-3.4.27 test/models/workarea/shipping/service_test.rb
workarea-core-3.5.4 test/models/workarea/shipping/service_test.rb
workarea-core-3.4.26 test/models/workarea/shipping/service_test.rb
workarea-core-3.5.3 test/models/workarea/shipping/service_test.rb
workarea-core-3.4.25 test/models/workarea/shipping/service_test.rb
workarea-core-3.5.2 test/models/workarea/shipping/service_test.rb
workarea-core-3.4.24 test/models/workarea/shipping/service_test.rb
workarea-core-3.5.1 test/models/workarea/shipping/service_test.rb