mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Add tests for Stripe::CreditCardRemover
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'stripe/credit_card_remover'
|
||||
|
||||
module Spree
|
||||
class CreditCardsController < BaseController
|
||||
def new_from_token
|
||||
|
||||
@@ -10,11 +10,8 @@ module Stripe
|
||||
|
||||
def call
|
||||
Stripe::CreditCardCloneDestroyer.new.destroy_clones(@credit_card)
|
||||
|
||||
stripe_customer = Stripe::Customer.retrieve(@credit_card.gateway_customer_profile_id, {})
|
||||
return unless stripe_customer
|
||||
|
||||
stripe_customer.delete unless stripe_customer.deleted?
|
||||
stripe_customer.delete if stripe_customer && !stripe_customer.deleted?
|
||||
end
|
||||
end
|
||||
end
|
||||
47
spec/lib/stripe/credit_card_remover_spec.rb
Normal file
47
spec/lib/stripe/credit_card_remover_spec.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
require 'spec_helper'
|
||||
require 'stripe/credit_card_remover'
|
||||
|
||||
describe Stripe::CreditCardRemover do
|
||||
let(:credit_card) { double('credit_card', gateway_customer_profile_id: 1) }
|
||||
|
||||
context 'Stripe customer exists' do
|
||||
context 'and is not deleted' do
|
||||
it 'deletes the credit card clone and the customer' do
|
||||
customer = double('customer', deleted?: false)
|
||||
allow(Stripe::Customer).to receive(:retrieve).and_return(customer)
|
||||
|
||||
expect_any_instance_of(Stripe::CreditCardCloneDestroyer).to receive(:destroy_clones).with(
|
||||
credit_card
|
||||
)
|
||||
expect(customer).to receive(:delete)
|
||||
Stripe::CreditCardRemover.new(credit_card).call
|
||||
end
|
||||
end
|
||||
|
||||
context 'and is deleted' do
|
||||
it 'deletes the credit card clone' do
|
||||
customer = double('customer', deleted?: true)
|
||||
allow(Stripe::Customer).to receive(:retrieve).and_return(customer)
|
||||
|
||||
expect_any_instance_of(Stripe::CreditCardCloneDestroyer).to receive(:destroy_clones).with(
|
||||
credit_card
|
||||
)
|
||||
expect(customer).not_to receive(:delete)
|
||||
Stripe::CreditCardRemover.new(credit_card).call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'Stripe customer does not exist' do
|
||||
it 'deletes the credit card clone' do
|
||||
allow(Stripe::Customer).to receive(:retrieve).and_return(nil)
|
||||
|
||||
expect_any_instance_of(Stripe::CreditCardCloneDestroyer).to receive(:destroy_clones).with(
|
||||
credit_card
|
||||
)
|
||||
Stripe::CreditCardRemover.new(credit_card).call
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user