mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-08 22:56:06 +00:00
Adapt specs to use stripe_sca_payment_method factory and delete stripe_connect_payment_method
This commit is contained in:
@@ -34,7 +34,7 @@ module OrderManagement
|
||||
end
|
||||
|
||||
context "when the payment method is a stripe payment method" do
|
||||
let(:payment_method) { create(:stripe_connect_payment_method) }
|
||||
let(:payment_method) { create(:stripe_sca_payment_method) }
|
||||
|
||||
context "and the card is already set (the payment source is a credit card)" do
|
||||
it "returns the pending payment with no change" do
|
||||
|
||||
@@ -753,7 +753,7 @@ describe Admin::SubscriptionsController, type: :controller do
|
||||
end
|
||||
|
||||
context "when other payment methods exist" do
|
||||
let!(:stripe) { create(:stripe_connect_payment_method, distributors: [shop]) }
|
||||
let!(:stripe) { create(:stripe_sca_payment_method, distributors: [shop]) }
|
||||
let!(:paypal) {
|
||||
Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress", distributor_ids: [shop.id])
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
|
||||
end
|
||||
|
||||
context "with Stripe payment where payment.process! errors out" do
|
||||
let!(:payment_method) { create(:stripe_connect_payment_method, distributors: [shop]) }
|
||||
let!(:payment_method) { create(:stripe_sca_payment_method, distributors: [shop]) }
|
||||
before do
|
||||
allow_any_instance_of(Spree::Payment).
|
||||
to receive(:process_offline!).
|
||||
|
||||
@@ -108,12 +108,12 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
context "on a StripeConnect payment method" do
|
||||
context "on a StripeSCA payment method" do
|
||||
let!(:user) { create(:user, enterprise_limit: 2) }
|
||||
let!(:enterprise1) { create(:distributor_enterprise, owner: user) }
|
||||
let!(:enterprise2) { create(:distributor_enterprise, owner: create(:user)) }
|
||||
let!(:payment_method) {
|
||||
create(:stripe_connect_payment_method, distributor_ids: [enterprise1.id, enterprise2.id],
|
||||
create(:stripe_sca_payment_method, distributor_ids: [enterprise1.id, enterprise2.id],
|
||||
preferred_enterprise_id: enterprise2.id)
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ module Spree
|
||||
{
|
||||
id: payment_method.id,
|
||||
payment_method: {
|
||||
type: "Spree::Gateway::StripeConnect",
|
||||
type: "Spree::Gateway::StripeSCA",
|
||||
preferred_enterprise_id: enterprise1.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,6 @@ FactoryBot.define do
|
||||
environment { 'test' }
|
||||
end
|
||||
|
||||
factory :stripe_connect_payment_method, class: Spree::Gateway::StripeConnect do
|
||||
name { 'StripeConnect' }
|
||||
environment { 'test' }
|
||||
distributors { [FactoryBot.create(:enterprise)] }
|
||||
preferred_enterprise_id { distributors.first.id }
|
||||
end
|
||||
|
||||
factory :stripe_sca_payment_method, class: Spree::Gateway::StripeSCA do
|
||||
name { 'StripeSCA' }
|
||||
environment { 'test' }
|
||||
|
||||
@@ -220,7 +220,7 @@ feature 'Subscriptions' do
|
||||
}
|
||||
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
|
||||
let!(:payment_method) {
|
||||
create(:stripe_connect_payment_method, name: 'Credit Card', distributors: [shop])
|
||||
create(:stripe_sca_payment_method, name: 'Credit Card', distributors: [shop])
|
||||
}
|
||||
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
|
||||
|
||||
@@ -387,7 +387,7 @@ feature 'Subscriptions' do
|
||||
}
|
||||
let!(:payment_method) { create(:payment_method, distributors: [shop]) }
|
||||
let!(:stripe_payment_method) {
|
||||
create(:stripe_connect_payment_method, name: 'Credit Card', distributors: [shop])
|
||||
create(:stripe_sca_payment_method, name: 'Credit Card', distributors: [shop])
|
||||
}
|
||||
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
|
||||
let!(:subscription) {
|
||||
@@ -536,7 +536,7 @@ feature 'Subscriptions' do
|
||||
let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) }
|
||||
let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop) }
|
||||
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
|
||||
let!(:payment_method) { create(:stripe_connect_payment_method, distributors: [shop]) }
|
||||
let!(:payment_method) { create(:stripe_sca_payment_method, distributors: [shop]) }
|
||||
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
|
||||
|
||||
before do
|
||||
|
||||
@@ -37,65 +37,6 @@ feature "Check out with Stripe", js: true do
|
||||
distributor.shipping_methods << [shipping_with_fee, free_shipping]
|
||||
end
|
||||
|
||||
context 'login in as user' do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
login_as(user)
|
||||
end
|
||||
|
||||
context "with Stripe Connect" do
|
||||
let!(:stripe_pm) do
|
||||
create(:stripe_connect_payment_method, distributors: [distributor])
|
||||
end
|
||||
|
||||
let!(:saved_card) do
|
||||
create(:credit_card,
|
||||
user_id: user.id,
|
||||
month: "01",
|
||||
year: "2025",
|
||||
cc_type: "visa",
|
||||
number: "1111111111111111",
|
||||
payment_method_id: stripe_pm.id,
|
||||
gateway_customer_profile_id: "i_am_saved")
|
||||
end
|
||||
|
||||
let!(:stripe_account) {
|
||||
create(:stripe_account, enterprise_id: distributor.id, stripe_user_id: 'some_id')
|
||||
}
|
||||
|
||||
let(:response_mock) { { id: "ch_1234", object: "charge", amount: 2000 } }
|
||||
|
||||
around do |example|
|
||||
original_stripe_connect_enabled = Spree::Config[:stripe_connect_enabled]
|
||||
example.run
|
||||
Spree::Config.set(stripe_connect_enabled: original_stripe_connect_enabled)
|
||||
end
|
||||
|
||||
before do
|
||||
stub_request(:post, "https://api.stripe.com/v1/charges")
|
||||
.with(basic_auth: ["sk_test_12345", ""])
|
||||
.to_return(status: 200, body: JSON.generate(response_mock))
|
||||
|
||||
visit checkout_path
|
||||
fill_out_form(shipping_with_fee.name, stripe_pm.name, save_default_addresses: false)
|
||||
end
|
||||
|
||||
it "allows use of a saved card" do
|
||||
# shows the saved credit card dropdown
|
||||
expect(page).to have_content I18n.t("spree.checkout.payment.stripe.used_saved_card")
|
||||
|
||||
# default card is selected, form element is not shown
|
||||
expect(page).to have_no_selector "#card-element.StripeElement"
|
||||
expect(page).to have_select 'selected_card', selected: "Visa x-1111 Exp:01/2025"
|
||||
|
||||
# allows checkout
|
||||
place_order
|
||||
expect(page).to have_content "Your order has been processed successfully"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "using Stripe SCA" do
|
||||
let!(:stripe_account) { create(:stripe_account, enterprise: distributor) }
|
||||
let!(:stripe_sca_payment_method) {
|
||||
|
||||
@@ -264,11 +264,11 @@ describe EnterprisesHelper, type: :helper do
|
||||
|
||||
context "when StripeConnect payment methods are present" do
|
||||
let!(:pm3) {
|
||||
create(:stripe_connect_payment_method, distributors: [distributor],
|
||||
create(:stripe_sca_payment_method, distributors: [distributor],
|
||||
preferred_enterprise_id: distributor.id)
|
||||
}
|
||||
let!(:pm4) {
|
||||
create(:stripe_connect_payment_method, distributors: [distributor],
|
||||
create(:stripe_sca_payment_method, distributors: [distributor],
|
||||
preferred_enterprise_id: some_other_distributor.id)
|
||||
}
|
||||
let(:available_payment_methods) { helper.available_payment_methods }
|
||||
|
||||
@@ -192,13 +192,13 @@ describe SubscriptionConfirmJob do
|
||||
end
|
||||
|
||||
context "Stripe Connect" do
|
||||
let(:stripe_connect_payment_method) { create(:stripe_connect_payment_method) }
|
||||
let(:stripe_connect_payment) {
|
||||
let(:stripe_sca_payment_method) { create(:stripe_sca_payment_method) }
|
||||
let(:stripe_sca_payment) {
|
||||
create(:payment, amount: 10, payment_method: stripe_connect_payment_method)
|
||||
}
|
||||
|
||||
before do
|
||||
allow(order).to receive(:pending_payments) { [stripe_connect_payment] }
|
||||
allow(order).to receive(:pending_payments) { [stripe_sca_payment] }
|
||||
allow(stripe_connect_payment_method).to receive(:purchase) { true }
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ module Stripe
|
||||
describe ProfileStorer do
|
||||
describe "create_customer_from_token" do
|
||||
let(:payment) { create(:payment) }
|
||||
let(:stripe_payment_method) { create(:stripe_connect_payment_method) }
|
||||
let(:stripe_payment_method) { create(:stripe_sca_payment_method) }
|
||||
let(:profile_storer) { Stripe::ProfileStorer.new(payment, stripe_payment_method.provider) }
|
||||
|
||||
let(:customer_id) { "cus_A123" }
|
||||
|
||||
@@ -1213,7 +1213,7 @@ describe Spree::Order do
|
||||
let!(:enterprise) { create(:enterprise) }
|
||||
let!(:order) { create(:order, distributor: enterprise) }
|
||||
let!(:payment_method) {
|
||||
create(:stripe_connect_payment_method, distributor_ids: [enterprise.id])
|
||||
create(:stripe_sca_payment_method, distributor_ids: [enterprise.id])
|
||||
}
|
||||
let!(:payment) { create(:payment, order: order, payment_method: payment_method) }
|
||||
|
||||
|
||||
@@ -904,8 +904,8 @@ describe Spree::Payment do
|
||||
context "to Stripe payments" do
|
||||
let(:shop) { create(:enterprise) }
|
||||
let(:payment_method) {
|
||||
create(:stripe_connect_payment_method, distributor_ids: [create(:distributor_enterprise).id],
|
||||
preferred_enterprise_id: shop.id)
|
||||
create(:stripe_sca_payment_method, distributor_ids: [create(:distributor_enterprise).id],
|
||||
preferred_enterprise_id: shop.id)
|
||||
}
|
||||
let(:payment) {
|
||||
create(:payment, order: order, payment_method: payment_method, amount: order.total)
|
||||
|
||||
Reference in New Issue
Block a user