summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorAlessandro Desantis <desa.alessandro@gmail.com>2020-10-09 14:04:49 +0200
committerAlessandro Desantis <desa.alessandro@gmail.com>2020-10-09 14:07:36 +0200
commitd7369ba04b3657e47e21e6d24af516886ef0dbc4 (patch)
treee8279d237a87c52a931721c182bf02f55e6370fa /spec/models
parentd0d2abca6c2f3c57ed16087a816d2638134208d8 (diff)
Fire events for subscription payment method updates
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/solidus_subscriptions/subscription_spec.rb16
-rw-r--r--spec/models/spree/wallet_payment_source_spec.rb18
2 files changed, 32 insertions, 2 deletions
diff --git a/spec/models/solidus_subscriptions/subscription_spec.rb b/spec/models/solidus_subscriptions/subscription_spec.rb
index 60a37e6..21e1015 100644
--- a/spec/models/solidus_subscriptions/subscription_spec.rb
+++ b/spec/models/solidus_subscriptions/subscription_spec.rb
@@ -64,6 +64,18 @@ RSpec.describe SolidusSubscriptions::Subscription, type: :model do
subscription: subscription,
)
end
+
+ it 'tracks payment method changes' do
+ stub_const('Spree::Event', class_spy(Spree::Event))
+
+ subscription = create(:subscription)
+ subscription.update!(payment_source: create(:credit_card))
+
+ expect(Spree::Event).to have_received(:fire).with(
+ 'solidus_subscriptions.subscription_payment_method_changed',
+ subscription: subscription,
+ )
+ end
end
describe '#cancel' do
@@ -445,7 +457,7 @@ RSpec.describe SolidusSubscriptions::Subscription, type: :model do
end
context 'when the subscription has no payment method' do
- it "returns the default source from the user's wallet" do
+ it "returns the default source from the user's wallet_payment_source" do
user = create(:user)
payment_source = create(:credit_card, gateway_customer_profile_id: 'BGS-123', user: user)
wallet_payment_source = user.wallet.add(payment_source)
@@ -487,7 +499,7 @@ RSpec.describe SolidusSubscriptions::Subscription, type: :model do
end
context 'when the subscription has no payment method' do
- it "returns the method from the default source in the user's wallet" do
+ it "returns the method from the default source in the user's wallet_payment_source" do
user = create(:user)
payment_source = create(:credit_card, gateway_customer_profile_id: 'BGS-123', user: user)
wallet_payment_source = user.wallet.add(payment_source)
diff --git a/spec/models/spree/wallet_payment_source_spec.rb b/spec/models/spree/wallet_payment_source_spec.rb
new file mode 100644
index 0000000..374e235
--- /dev/null
+++ b/spec/models/spree/wallet_payment_source_spec.rb
@@ -0,0 +1,18 @@
+RSpec.describe Spree::WalletPaymentSource do
+ describe 'setting it as the default' do
+ it 'reports a payment method changed event for subscriptions that use the default payment source' do
+ stub_const('Spree::Event', class_spy(Spree::Event))
+ user = create(:user)
+ subscription = create(:subscription, user: user)
+ payment_source = create(:credit_card, user: user)
+ wallet_payment_source = user.wallet.add(payment_source)
+
+ user.wallet.default_wallet_payment_source = wallet_payment_source
+
+ expect(Spree::Event).to have_received(:fire).with(
+ 'solidus_subscriptions.subscription_payment_method_changed',
+ subscription: subscription,
+ )
+ end
+ end
+end