Skip to content

Commit

Permalink
Use ApiHelper to DRY calls to JSON.parse in spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed Sep 2, 2019
1 parent c4fca36 commit f5ba784
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions spec/requests/checkout/stripe_connect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe "checking out an order with a Stripe Connect payment method", type: :request do
include ShopWorkflow
include AuthenticationWorkflow
include OpenFoodNetwork::ApiHelper

let!(:order_cycle) { create(:simple_order_cycle) }
let!(:enterprise) { create(:distributor_enterprise) }
Expand Down Expand Up @@ -111,8 +112,6 @@
it "should process the payment without storing card details" do
put update_checkout_path, params

json_response = JSON.parse(response.body)

expect(json_response["path"]).to eq spree.order_path(order)
expect(order.payments.completed.count).to be 1

Expand All @@ -137,8 +136,6 @@

expect(response.status).to be 400

json_response = JSON.parse(response.body)

expect(json_response["flash"]["error"]).to eq "charge-failure"
expect(order.payments.completed.count).to be 0
end
Expand Down Expand Up @@ -172,8 +169,6 @@
it "should process the payment, and stores the card/customer details" do
put update_checkout_path, params

json_response = JSON.parse(response.body)

expect(json_response["path"]).to eq spree.order_path(order)
expect(order.payments.completed.count).to be 1

Expand All @@ -198,8 +193,6 @@

expect(response.status).to be 400

json_response = JSON.parse(response.body)

expect(json_response["flash"]["error"])
.to eq(I18n.t(:spree_gateway_error_flash_for_checkout, error: 'store-failure'))
expect(order.payments.completed.count).to be 0
Expand All @@ -216,8 +209,6 @@

expect(response.status).to be 400

json_response = JSON.parse(response.body)

expect(json_response["flash"]["error"]).to eq "charge-failure"
expect(order.payments.completed.count).to be 0
end
Expand All @@ -234,8 +225,6 @@

expect(response.status).to be 400

json_response = JSON.parse(response.body)

expect(json_response["flash"]["error"]).to eq "token-failure"
expect(order.payments.completed.count).to be 0
end
Expand Down Expand Up @@ -282,8 +271,6 @@
it "should process the payment, and keep the profile ids and other card details" do
put update_checkout_path, params

json_response = JSON.parse(response.body)

expect(json_response["path"]).to eq spree.order_path(order)
expect(order.payments.completed.count).to be 1

Expand All @@ -308,8 +295,6 @@

expect(response.status).to be 400

json_response = JSON.parse(response.body)

expect(json_response["flash"]["error"]).to eq "charge-failure"
expect(order.payments.completed.count).to be 0
end
Expand All @@ -325,8 +310,6 @@

expect(response.status).to be 400

json_response = JSON.parse(response.body)

expect(json_response["flash"]["error"]).to eq "token-error"
expect(order.payments.completed.count).to be 0
end
Expand Down

0 comments on commit f5ba784

Please sign in to comment.