Files
ubicloud/spec/model/payment_method_spec.rb
Enes Cakir b7f2cae5a8 Remove payment method serializer
We've stopped using serializers for web routes, so I removed
`Serializers::PaymentMethod`.

I moved the Stripe data mapping to the `stripe_data` method, which now
returns the used hash instead of the raw data.
2025-03-29 09:49:33 +03:00

32 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require_relative "spec_helper"
RSpec.describe PaymentMethod do
subject(:payment_method) { described_class.create_with_id(stripe_id: "pm_1234567890") }
it "return Stripe Data if Stripe enabled" do
allow(Config).to receive(:stripe_secret_key).and_return("secret_key")
expect(Stripe::PaymentMethod).to receive(:retrieve).with("pm_1234567890").and_return({"id" => "pm_1234567890", "card" => {"brand" => "Visa", "last4" => "1234", "exp_month" => 12, "exp_year" => 2023}})
expect(payment_method.stripe_data).to eq({"brand" => "Visa", "last4" => "1234", "exp_month" => 12, "exp_year" => 2023})
end
it "not return Stripe Data if Stripe not enabled" do
allow(Config).to receive(:stripe_secret_key).and_return(nil)
expect(Stripe::PaymentMethod).not_to receive(:retrieve)
expect(payment_method.stripe_data).to be_nil
end
it "delete Stripe payment method if Stripe enabled" do
allow(Config).to receive(:stripe_secret_key).and_return("secret_key")
expect(Stripe::PaymentMethod).to receive(:detach).with("pm_1234567890")
payment_method.destroy
end
it "not delete Stripe payment method if Stripe not enabled" do
allow(Config).to receive(:stripe_secret_key).and_return(nil)
expect(Stripe::PaymentMethod).not_to receive(:detach)
payment_method.destroy
end
end