Sha256: c824e93fde2aa938456c41ffbde262935c8a99d0a7db208fd0859f2c8b4dd9fb

Contents?: true

Size: 1.5 KB

Versions: 8

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe SolidusStripe::AddressFromParamsService do
  let(:service) { described_class.new(params, user) }
  let(:state) { create :state }

  describe '#call' do
    let(:params) do
      {
        country: state.country.iso,
        region: state.abbr,
        recipient: 'Clark Kent',
        city: 'Metropolis',
        postalCode: '12345',
        addressLine: [ '12, Lincoln Rd']
      }
    end

    subject { service.call }

    context "when there is no user" do
      let(:user) { nil }

      it "returns a non-persisted address model" do
        expect(subject).to be_new_record
      end
    end

    context "when there is a user" do
      let(:user) { create :user }

      context "when the user has an address compatible with the params" do
        before do
          user.addresses << create(
            :address, city: params[:city],
            zipcode: params[:postalCode],
            firstname: 'Clark',
            lastname: 'Kent',
            address1: params[:addressLine].first,
            address2: nil
          )
        end

        it "returns an existing user's address" do
          expect(subject).to eql user.addresses.first
        end
      end

      context "when no user's address is compatible with the params" do
        before do
          user.addresses << create(:address)
        end

        it "returns a non-persisted address model" do
          expect(subject).to be_new_record
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
solidus_stripe-3.2.1 spec/models/solidus_stripe/address_from_params_service_spec.rb
solidus_stripe-4.0.0 spec/models/solidus_stripe/address_from_params_service_spec.rb
solidus_stripe-3.2.0 spec/models/solidus_stripe/address_from_params_service_spec.rb
solidus_stripe-3.1.0 spec/models/solidus_stripe/address_from_params_service_spec.rb
solidus_stripe-3.0.0 spec/models/solidus_stripe/address_from_params_service_spec.rb
solidus_stripe-2.1.0 spec/models/solidus_stripe/address_from_params_service_spec.rb
solidus_stripe-2.0.0 spec/models/solidus_stripe/address_from_params_service_spec.rb
solidus_stripe-1.1.0 spec/models/solidus_stripe/address_from_params_service_spec.rb