Use better credit card factory for subs specs

The specs for subscriptions were creating simple one-time-use credit
cards. They should not be used for subscriptions. After this was fixed
in previous commits, these integration tests failed. Now we use a new
factory that mimics stored credit cards that can be used for
subscriptions.
This commit is contained in:
Maikel Linke
2019-06-07 17:40:13 +10:00
committed by luisramos0
parent b3b8cb778f
commit 5c72c35060
3 changed files with 11 additions and 5 deletions

View File

@@ -510,6 +510,12 @@ FactoryBot.define do
end
end
# A card that has been added to the user's profile and can be re-used.
factory :stored_credit_card, parent: :credit_card do
gateway_customer_profile_id "cus_F2T..."
gateway_payment_profile_id "card_1EY..."
end
factory :stripe_payment_method, :class => Spree::Gateway::StripeConnect do
name 'Stripe'
environment 'test'

View File

@@ -143,7 +143,7 @@ feature 'Subscriptions' do
context 'creating a new subscription' do
let(:address) { create(:address) }
let!(:customer_user) { create(:user) }
let!(:credit_card1) { create(:credit_card, user: customer_user, cc_type: 'visa', last_digits: 1111, month: 10, year: 2030) }
let!(:credit_card1) { create(:stored_credit_card, user: customer_user, cc_type: 'visa', last_digits: 1111, month: 10, year: 2030) }
let!(:customer) { create(:customer, enterprise: shop, bill_address: address, user: customer_user, allow_charges: true) }
let!(:test_product) { create(:product, supplier: shop) }
let!(:test_variant) { create(:variant, product: test_product, unit_value: "100", price: 12.00, option_values: []) }
@@ -413,7 +413,7 @@ feature 'Subscriptions' do
describe "allowed variants" do
let!(:customer) { create(:customer, enterprise: shop, allow_charges: true) }
let!(:credit_card) { create(:credit_card, user: customer.user) }
let!(:credit_card) { create(:stored_credit_card, user: customer.user) }
let!(:shop_product) { create(:product, supplier: shop) }
let!(:shop_variant) { create(:variant, product: shop_product, unit_value: "2000") }
let!(:permitted_supplier) do

View File

@@ -145,7 +145,7 @@ describe Spree.user_class do
end
context "when the user has one credit card" do
let!(:card) { create(:credit_card, user: user) }
let!(:card) { create(:stored_credit_card, user: user) }
it "should be assigned as the default and be returned" do
expect(card.reload.is_default).to be true
@@ -154,8 +154,8 @@ describe Spree.user_class do
end
context "when the user has more than one card" do
let!(:non_default_card) { create(:credit_card, user: user) }
let!(:default_card) { create(:credit_card, user: user, is_default: true) }
let!(:non_default_card) { create(:stored_credit_card, user: user) }
let!(:default_card) { create(:stored_credit_card, user: user, is_default: true) }
it "returns the card which is specified as the default" do
expect(user.default_card.id).to be default_card.id