Sha256: 38cdded96d41a3749473a7da185e9a0e2c0038e6df2c0e2dc7c222d39643e526

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

RSpec.describe SolidusEasypost::ShippingMethodSelector do
  describe '#shipping_method_for' do
    context 'when a shipping method for the given carrier and service exists' do
      it 'returns the existing shipping method' do
        shipping_method = create(:shipping_method, carrier: 'USPS', service_level: 'Express')
        easypost_rate = EasyPost::Rate.construct_from('carrier' => 'USPS', 'service' => 'Express')

        selector = described_class.new
        selected_shipping_method = selector.shipping_method_for(easypost_rate)

        expect(selected_shipping_method).to eq(shipping_method)
      end
    end

    context 'when a shipping method for the given carrier and service does not exist' do
      it 'creates a new shipping method' do
        shipping_category = create(:shipping_category)
        easypost_rate = EasyPost::Rate.construct_from('carrier' => 'USPS', 'service' => 'Express')

        selector = described_class.new
        selected_shipping_method = selector.shipping_method_for(easypost_rate)

        expect(selected_shipping_method).to have_attributes(
          name: 'USPS Express',
          carrier: 'USPS',
          service_level: 'Express',
          shipping_categories: [shipping_category],
          available_to_users: false,
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_easypost-3.0.0 spec/solidus_easypost/shipping_method_selector_spec.rb