Sha256: 8e674ad81cbad8ea01d92a4d14c94df3d8bf93eb6a3081843a2a548b927b0df6

Contents?: true

Size: 1.44 KB

Versions: 62

Compression:

Stored size: 1.44 KB

Contents

require 'test_helper'

module Workarea
  class ShippingOptionTest < TestCase
    def test_from_rate_estimate
      rate_estimate = ActiveShipping::RateEstimate.new(
        Address.new,
        Address.new,
        'UPS',
        'Ground',
        service_code: '03',
        total_price: 700,
        currency: 'USD'
      )

      create_shipping_service(carrier: 'UPS', name: 'Ground', tax_code: '001')
      create_shipping_service(carrier: 'UPS', name: '2 Day', tax_code: '002')

      result = ShippingOption.from_rate_estimate(rate_estimate)
      assert_equal('UPS', result.carrier)
      assert_equal('Ground', result.name)
      assert_equal('03', result.service_code)
      assert_equal('001', result.tax_code)
      assert_equal(7.to_m, result.price)
    end

    def test_price
      shipping_service = create_shipping_service(rates: [{ price: 3.to_m }])

      adjustment = PriceAdjustment.new(amount: -1.to_m)
      option = ShippingOption.new(
        shipping_service.attributes.merge(price: 3.to_m)
      )

      option.price_adjustments = [adjustment]

      assert_equal(2.to_m, option.price)
    end

    def test_price_guards_against_price_adjustments
      shipping_service = create_shipping_service(rates: [{ price: 3.to_m }])

      adjustment = PriceAdjustment.new(amount: -10.to_m)
      option = ShippingOption.new(shipping_service.attributes)
      option.price_adjustments = [adjustment]

      assert_equal(0.to_m, option.price)
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

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