Sha256: bf72232a014348bdcd7c359f27496903bbb4b4c8e0e13496861551e9fa615d7f

Contents?: true

Size: 1.91 KB

Versions: 7

Compression:

Stored size: 1.91 KB

Contents

require 'solidus_paypal_commerce_platform_spec_helper'

RSpec.describe SolidusPaypalCommercePlatform::PaypalAddress, type: :model do
  let(:order) { create(:order) }
  let(:original_address) { create(:address) }
  let(:address) { create(:address, name_attributes) }
  let(:params) {
    {
      updated_address: {
        admin_area_1: address.state.abbr,
        admin_area_2: address.city,
        address_line_1: address.address1,
        address_line_2: address.address2,
        postal_code: address.zipcode,
        country_code: address.country.iso
      },
      recipient: {
        name: {
          given_name: "Alexander",
          surname: "Hamilton"
        }
      }
    }
  }

  describe "#update_address" do
    subject{ order.ship_address }

    it "formats PayPal addresses correctly" do
      order.ship_address = original_address

      described_class.new(order).update(params)

      expect(subject.state).to eq address.state
      expect(subject.city).to eq address.city
      expect(subject.address1).to eq address.address1
      expect(subject.address2).to eq address.address2
      expect(subject.zipcode).to eq address.zipcode
      expect(subject.country).to eq address.country
      if SolidusSupport.combined_first_and_last_name_in_address?
        expect(subject.name).to eq address.name
      else
        expect(subject.firstname).to eq address.firstname
        expect(subject.lastname).to eq address.lastname
      end
      expect(subject.phone).to eq original_address.phone
    end

    context "when no address exists" do
      it "produce a valid address" do
        order.ship_address = nil

        described_class.new(order).update(params)

        expect(subject).to be_present
      end
    end
  end

  def name_attributes
    if SolidusSupport.combined_first_and_last_name_in_address?
      { name: "Alexander Hamilton" }
    else
      { firstname: "Alexander", lastname: "Hamilton" }
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_paypal_commerce_platform-1.0.3 spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb
solidus_paypal_commerce_platform-1.0.2 spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb
solidus_paypal_commerce_platform-1.0.1 spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb
solidus_paypal_commerce_platform-1.0.0 spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb
solidus_paypal_commerce_platform-1.0.0.beta3 spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb
solidus_paypal_commerce_platform-1.0.0.beta2 spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb
solidus_paypal_commerce_platform-1.0.0.beta1 spec/models/solidus_paypal_commerce_platform/paypal_address_spec.rb