test: Add specs for the stripe_card_options helper method, verifying card formatting and month padding.

This commit is contained in:
Zil Norvilis
2026-02-25 19:49:10 +02:00
parent 0bc4b1c885
commit 58520a0c4c

View File

@@ -193,4 +193,25 @@ RSpec.describe CheckoutHelper do
end
end
end
describe "#stripe_card_options" do
let(:year) { Time.zone.now.year + 1 }
let(:card) { create(:credit_card, cc_type: 'visa', last_digits: '1111', month: 1, year:) }
let(:cards) { [card] }
it "formats credit cards for Stripe options" do
options = helper.stripe_card_options(cards)
expect(options).to eq([
["visa 1111 Exp:01/#{year}", card.id]
])
end
it "zero-pads the month" do
card.update(month: 5)
options = helper.stripe_card_options(cards)
expect(options.first.first).to match(%r{05/#{year}})
end
end
end