Sha256: 843bf1e2b882a67cd135eeae5d1e28a6fccaf7bc0b8424c7fde45e16a7b7edda

Contents?: true

Size: 1.84 KB

Versions: 62

Compression:

Stored size: 1.84 KB

Contents

require 'test_helper'

module Workarea
  class Checkout
    class ShippingOptionsTest < TestCase
      setup :shipping_service, :setup_order

      def order
        @order ||= Order.new(
          email: 'user@workarea.com',
          items: [{ product_id: 'PRODUCT', sku: 'SKU' }]
        )
      end

      def shipping
        @shipping ||= Shipping.new(
          order_id: order.id,
          address: {
            first_name: 'Ben',
            last_name: 'Crouse',
            street: '22 S. 3rd St.',
            street_2: 'Second Floor',
            city: 'Philadelphia',
            region: 'PA',
            postal_code: '19106',
            country: 'US',
            phone_number: '2159251800'
          }
        )
      end

      def shipping_options
        @shipping_options ||= ShippingOptions.new(order, shipping)
      end

      def shipping_service
        @shipping_service ||= create_shipping_service
      end

      def setup_order
        create_shipping_service
        create_pricing_sku(id: 'SKU', prices: [{ regular: 5.to_m }])
      end

      def test_available
        options = shipping_options.available
        assert_equal(ShippingOption, options.first.class)
      end

      def test_valid?
        refute(shipping_options.valid?)

        attrs = shipping_options.available.first.to_h
        shipping.apply_shipping_service(attrs)
        assert(shipping_options.valid?)
        assert(shipping.errors[:shipping_service].blank?)

        shipping.shipping_service.name = 'asdf'
        refute(shipping_options.valid?)
        assert(shipping.errors[:shipping_service].present?)

        attrs = shipping_options.available.first.to_h
        attrs[:base_price] = 0

        shipping.apply_shipping_service(attrs)
        refute(shipping_options.valid?)
        assert(shipping.errors[:shipping_service].present?)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

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