Skip to content

Commit

Permalink
Replace payment_method_spec instance_double Order with build_stubbed
Browse files Browse the repository at this point in the history
To reduce having unnecessary information on tests that do not explicitly
involve Spree::Order checkout steps.
  • Loading branch information
RyanofWoods committed Dec 2, 2021
1 parent 0a18987 commit d22dd9d
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,42 +77,36 @@ def Struct(data) # rubocop:disable Naming/MethodName
describe '.javascript_sdk_url' do
subject(:url) { URI(paypal_payment_method.javascript_sdk_url(order: order)) }

context 'when checkout_steps include "confirm"' do
let(:order) { instance_double(Spree::Order, checkout_steps: { "confirm" => "bar" }) }
let(:order) { build_stubbed(:order) }

context 'when checkout_steps include "confirm"' do
it 'sets autocommit' do
expect(url.query.split("&")).to include("commit=false")
end
end

context 'when checkout_steps does not include "confirm"' do
let(:order) { instance_double(Spree::Order, checkout_steps: { "foo" => "bar" }) }

it 'disables autocommit' do
allow(order).to receive(:checkout_steps).and_return([:address, :delivery, :payment])
expect(url.query.split("&")).to include("commit=true")
end
end

context 'when checkout_steps does not include "delivery"' do
let(:order) { instance_double(Spree::Order, checkout_steps: { "foo" => "bar" }) }

it 'disables autocommit' do
allow(order).to receive(:checkout_steps).and_return([:address, :confirm, :payment])
expect(url.query.split("&")).to include("shipping_preference=NO_SHIPPING")
end
end

context 'when messaging is turned on' do
let(:order) { instance_double(Spree::Order, checkout_steps: { "foo" => "bar" }) }

it 'includes messaging component' do
paypal_payment_method.preferences.update(display_credit_messaging: true)
expect(url.query.split("&")).to include("components=buttons%2Cmessages")
end
end

context 'when messaging is turned off' do
let(:order) { instance_double(Spree::Order, checkout_steps: { "foo" => "bar" }) }

it 'only includes buttons components' do
paypal_payment_method.preferences.update(display_credit_messaging: false)
expect(url.query.split("&")).not_to include("messages")
Expand Down

0 comments on commit d22dd9d

Please sign in to comment.